【发布时间】:2019-07-15 20:27:09
【问题描述】:
我正在我的 Android 应用中进行 Firebase 云消息传递设置。我不是第一次做,我做了很多次。但是这次我在尝试获取设备令牌时遇到了一个奇怪的错误“无效的发件人 ID”。我从来没有在我的项目中使用过任何发件人 ID,除了项目编号默认存在于 google-services.json 文件中。请帮助我摆脱了这个
.我正在使用此方法生成令牌。我在我的项目中添加了 google-services.json 文件
FirebaseInstanceId.getInstance().getInstanceId()
.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
@Override
public void onComplete(@NonNull Task<InstanceIdResult> task) {
if (!task.isSuccessful()) {
Toast.makeText(WelcomeActivity.this,task.getException().getMessage(),Toast.LENGTH_LONG).show();
Log.w("getInstanceId failed", task.getException());
return;
}
// Get new Instance ID token
String token = task.getResult().getToken();
Log.v("sssskkkk",token);
}
});
我在我的项目中使用以下依赖项
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
api fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.firebase:firebase-messaging:17.3.4'
testImplementation('com.android.support.test.espresso:espresso-core:2.2.2')
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'me.relex:circleindicator:1.2.2@aar'
implementation 'org.immutables:gson:2.4.0'
implementation 'com.android.volley:volley:1.1.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.android.support:multidex:1.0.3'
testImplementation 'junit:junit:4.12'
implementation 'com.borjabravo:readmoretextview:2.0.1'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'com.github.mabbas007:TagsEditText:1.0.5'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:support-core-utils:28.0.0'
implementation 'com.karumi:dexter:4.2.0'
我很确定在 Firebase 云消息传递的实现中我没有遗漏任何东西。此外,当我在具有相同包名称的不同项目中使用相同的 google-services.json 时,一切正常。
【问题讨论】:
标签: java android firebase-cloud-messaging