![](/img/trans.png)
[英]FCM Notification is not received when my app foreground service is killed
[英]FCM notification not received whether the app in background or foreground
使用Firebase通知撰寫人或郵遞員發送通知后未收到通知,盡管我都從兩個人獲得了成功的反饋
我已經關注了如何實現它的firebase文檔。
我也曾嘗試回答類似問題,但仍未收到通知
仍然,當我使用郵遞員時,我得到了成功的答復,但是出現了通知提示
AndroiManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.fcmpushnotification">
<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=".helper.MyFirebaseMessageService"
android:exported="false"
>
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
</manifest>
FCM服務等級
public class MyFirebaseMessageService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.d("FIREBASETOKEN", "testing if method is called ");
//checking if , there is any notification
if (remoteMessage.getNotification()!=null) {
String title = remoteMessage.getNotification().getTitle();
String message = remoteMessage.getNotification().getBody();
NotificationHelper helper = new NotificationHelper();
helper.setBody(message); helper.setTitle(title);
NotificationHelper.displayNotification(getApplicationContext(), helper);
Log.d("FIREBASETOKEN", "notification is not empty");
}else {
//Toast.makeText( , "notification is empty" , Toast.LENGTH_LONG).show();
Log.d("FIREBASETOKEN", "notification is empty");
}
}
}
使用郵遞員的身體 {
"to" : "cI1AZOAfrv8:APA91bFQUcKD6gGIfCHplDXCMCFvgk9K2b-jwsN2g_3omDMM0_y_twT0SpqWYzoBWhzWYhcsedbNZCfsygBqDVT5nECOL9sBM7mKFn_4oxry7H8P_rxVvvPRCTXWitxw4V2xd2Gkbmtb",
"collapse_key" : "type_a",
"notification" : {
"body" : "Body of Your Notification",
"title": "Title of Your Notification"
}
}
響應
{
"multicast_id": 6756762729932992317,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:1562751631028566%77e482e477e482e4"
}
]
}
我希望收到通知,並且要記錄onMessageReceived()
中的日志,但沒有任何反應
似乎您缺少互聯網許可。 向清單添加以下權限
<uses-permission android:name="android.permission.INTERNET" />
並且您的設備上的互聯網必須打開。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.