[英]Cant receive Notifications from FCM while the app is in Foreground state
[英]Cant receive push notifications from Intercom, FCM
對講機推送通知有問題。 我無法在設備上收到對講機的任何推送通知; 從 FCM 發送的標准通知可以按預期完美運行。
已按照本教程進行操作,並按照建議將服務器密鑰添加到對講機。
CloudMessaging.java
public class CloudMessaging extends FirebaseMessagingService {
private final IntercomPushClient intercomPushClient = new IntercomPushClient();
public void getFirebaseInstanceID() {
FirebaseInstanceId.getInstance().getInstanceId()
.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
@Override
public void onComplete(@NonNull Task<InstanceIdResult> task) {
if (!task.isSuccessful()) {
Log.w(TAG, "getInstanceId failed", task.getException());
return;
}
intercomPushClient.sendTokenToIntercom(application, token);
);
}
}
});
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Map message = remoteMessage.getData();
if (intercomPushClient.isIntercomPush(message)) {
Log.d(TAG, "Intercom message received");
intercomPushClient.handlePush(getApplication(), message);
} else {
super.onMessageReceived(remoteMessage);
}
}
Gradle
<service
android:name="com.google.firebase.messaging.FirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name=".CloudMessaging"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
您只需要 Gradle 文件中的一個"com.google.firebase.MESSAGING_EVENT"
實例。 就我而言,我堅持使用.CloudMessaging
,因為這是處理對講通知的地方,如上所示。 我的CloudMessaging
class 需要有一個帶有 0 個輸入字段的公共構造函數才能在收到通知時打開。 例如。
Gradle文件
<service
android:name=".CloudMessaging"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
CloudMessaging Class
public CloudMessaging() {
//dont delete or you wont get push notifications buddy
}
CloudMessaging(Context context, Application application) {
this.context = context;
this.application = application;
sharedPref = context.getSharedPreferences(FCM_ID_SHAREDPREF, MODE_PRIVATE);
}
下一個最重要的事情是確保您使用正確的對講機 SDK。 我最初實現了一個沒有推送通知功能的“基礎”sdk。 確保您擁有完整的 sdk。
壞 SDK
dependencies {
implementation 'io.intercom.android:intercom-sdk-base:x.x.+'
}
好SDK
dependencies {
implementation 'io.intercom.android:intercom-sdk:x.x.+'
implementation 'com.google.firebase:firebase-messaging:x.+'
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.