检查Firebase账号设置 确保Firebase账户已正确设置并已将其集成到您的应用程序中。 您可以登录Firebase控制台,检查设置并确保您的应用程序的要素(如包名、App ID)已正确设置。
检查Android权限 确保您的应用程序已获得必要的权限来访问Firebase。 在AndroidManifest.xml文件中检查以下权限:
dependencies {
implementation 'com.google.firebase:firebase-messaging:21.1.0'
}
android {
defaultConfig {
...
manifestPlaceholders = [
'FCM_SENDER_ID': 'YOUR_FCM_SENDER_ID'
]
}
}
dependencies {
implementation 'com.google.firebase:firebase-messaging:21.1.0'
}
apply plugin: 'com.google.gms.google-services'
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// ...
// Not getting messages here? See why this may be: https://goo.gl/39bRNJ
Log