【发布时间】:2017-10-30 11:07:11
【问题描述】:
AndroidStudio 中的 FCM 设置 - 工具 - Cloud Messaging 中的 Firebase 助手设置成功。因此,设置已更正但未生成令牌。通过 MainActivity 中的令牌显示在 logcat 和 Config 类中未生成令牌,但其显示为空。运行问题继续后卸载的应用程序。我也尝试了不同的模拟器,但没有任何解决方案。
MyFirebaseInstanceIDService.java
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
private static final String TAG = "MyFirebaseIIDService";
@Override
public void onTokenRefresh() {
String newToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + newToken);
Config.TOKEN = newToken;
}
}
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
</application>
build.gradle(项目级)
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.0.0'
}
build.gradle(应用级)
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.firebase:firebase-messaging:10.0.1'
testCompile 'junit:junit:4.12'
compile 'com.squareup.okhttp:okhttp:2.0.0'
}
apply plugin: 'com.google.gms.google-services'
【问题讨论】:
-
卸载应用并重试...
-
您的应用目录下是否有 googleservies.json 文件?
-
是的,app目录下的googleservies.json文件
标签: android push-notification firebase-cloud-messaging