Firebase甚至在更改应用程序包名称后发送通知

时间:2017-12-29 05:36:53

标签: android firebase-cloud-messaging

我有一个奇怪的怀疑。 我在我的Android应用程序中使用FCM。假设我的应用程序包的名称是-- files ending with .suo and .user -- folders bin and obj ,我使用com.example.example从FCM获得google-service.json文件,我收到令牌和通知也正常。 但是现在我将包括com.example.example包括com.sample.sample,包括com.example.example文件在内的每个位置,我也可以在这里得到令牌。 现在,如果我使用包google-service.json转到FCM项目并从那里ping通,那么通知将发送到com.example.example 我怀疑它应该不对吗? 请帮帮我。

这是我的app level gradle,包含在firbase注册的包名:

com.sample.sample

这是我复制的项目的gradle,包名重构:

apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
    applicationId "com.pushnotification.fcmnotifier"
    minSdkVersion 22
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:mediarouter-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.google.android.gms:play-services:11.8.0'
compile 'com.google.firebase:firebase-messaging:11.8.0'
}

apply plugin: 'com.google.gms.google-services'

3 个答案:

答案 0 :(得分:1)

这就是firebase支持对此问题的回复。希望它有所帮助。

感谢您与Firebase支持联系。

您的情况似乎与此SO线程有关。正如我引用我们的一位工程师那样,"请注意,Firebase不使用Java代码中的实际包名,而是使用应用程序的build.gradle文件中的applicationId:.....但如果您将代码重构为不同的包,应用程序ID不会更新。这就解释了为什么应用程序将在重构之后继续工作。"

如果您需要进一步的帮助,请告诉我。

此致 理查德

这是firebase的最终结论:

我已经与我们的团队讨论了这个问题,结果发现FCM使用GMP App Id而不是包名。这就是为什么即使您重构了applicationId和包名,通知仍然可以工作的原因。我还建议您为Android应用的不同版本使用不同的Firebase应用,而不是仅使用一个。

此致 理查德

答案 1 :(得分:0)

如果您要在应用的build.gradle文件中更改应用程序ID ,则需要在firebase控制台中使用新ID注册新应用。 然后下载该应用程序的google-service.json文件。

在json文件中手动更改应用程序ID将不起作用。

另请注意,如果您只更改包名称,即清单文件中使用的名称, Google将无法识别。在build.gradle中更改应用程序ID需要具有新的应用程序ID。

有关详情,请查看:https://developer.android.com/studio/build/application-id.html

答案 2 :(得分:0)

我不确定这一点,但可能是原因背后这个问题是

更改Package名称后,您需要更改Package表格应用级别草稿文件,在applicationId文件

之后每个package_name = "com.sample.sample"(新重新package名称)更新后

希望这会对你有所帮助

相关问题