[英]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.