在某些设备(如小米oppo,vivo,Redmi和某些操作系统(氧气操作系统,彩色操作系统,MIUI等)中关闭应用程序时,FCM推送通知不起作用 [英] FCM Push Notification not working when app close in some of the devices like xiaomi oppo, vivo,Redmi and some of OS (Oxygen OS, Color OS, MIUI etc)

查看:410
本文介绍了在某些设备(如小米oppo,vivo,Redmi和某些操作系统(氧气操作系统,彩色操作系统,MIUI等)中关闭应用程序时,FCM推送通知不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些设备(如小米,oppo,vivo,Redmi和某些操作系统(氧气操作系统,彩色操作系统,MIUI等))中关闭应用程序时,FCM推送通知不起作用.

FCM Push Notification not working when app close in some of the devices like xiaomi, oppo, vivo,Redmi and some of OS (Oxygen OS, Color OS, MIUI etc).

但是其他设备和操作系统运行良好.

But other devices and OS working good.

有人有经验吗?

Android结束代码.

公共类MyFirebaseMessagingService扩展了FirebaseMessagingService {

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) {
    Log.e(TAG, "From: " + remoteMessage.getFrom());


}

}

公共类MyFirebaseInstanceIDService扩展了FirebaseInstanceIdService {

public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {

private static final String TAG = MyFirebaseInstanceIDService.class.getName();

@Override
public void onTokenRefresh() {
    // Get updated InstanceID token.
    String refreshedToken = FirebaseInstanceId.getInstance().getToken();
    Log.d(TAG, "Refreshed token: " + refreshedToken);

    // If you want to send messages to this application instance or
    // manage this apps subscriptions on the server side, send the
    // Instance ID token to your app server.
    sendRegistrationToServer(refreshedToken);
}

private void sendRegistrationToServer(String refreshedToken) {


}

}

<service
        android:name=".MyFirebaseInstanceIDService"
        android:stopWithTask="false"
        >
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
    </service>

    <service
        android:name=".MyFirebaseMessagingService"
        android:stopWithTask="false"
        >
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"/>
        </intent-filter>
    </service>

服务器结束代码

{
"notification": {
"title": "FCM Kazi",
"body": "FCM bdoy1 ",
"sound": "default",
"click_action": "FCM_PLUGIN_ACTIVITY",
"icon": "fcm_push_icon"
},
"data": {
"param1": "value1",
"param2": "value2"
},
"to": "cVL4I6upF-g:APA91bE7EFv3apIMHuEL_oCoVvhhrUw-ftM6S11RE9HOF58wf3ewYkDUh9wUhUCMIa6zoftOgGH5HWt0rPKVHw2OShn06tIESFnGo9u8rooJ9qfiXQQlg-zZzjgi0cQ64BUaZnUCM09R",
"priority": "high"
}

推荐答案

仅使用数据播放负载并删除通知播放负载.数据播放量总是会收到应用程序打开或关闭的问题.通知播放负载仅在应用程序处于前台状态时才起作用.而且,如果您没有在少数设备上接收信息,请转到设备设置并启用该应用程序的接收通知.默认情况下,很少有制造商不允许通知.

Use only data playload and remove notification playload. Data playload always receive wheather app is open or close doesn't matter. Notification playload works only if app is in forground. And if you are not receiving on few devices go to device settings and enable receive notification for that app. Few manufacturer doesn't allow notification by default.

这篇关于在某些设备(如小米oppo,vivo,Redmi和某些操作系统(氧气操作系统,彩色操作系统,MIUI等)中关闭应用程序时,FCM推送通知不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆