android fcm 中未出现 oppo、vivo 应用程序终止通知

2024-04-24

在摩托罗拉测试应用程序,三星在应用程序被杀死时工作正常。但是当我在vivo测试应用程序时,如果应用程序被破坏,oppo将无法工作。

 public void onMessageReceived(RemoteMessage remoteMessage) {
    Log.e(TAG, "From: " + remoteMessage.getFrom());

    if (remoteMessage == null)
        return;

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.e(TAG, "Notification Body: " + remoteMessage.getNotification().getBody());
        //  handleNotification(remoteMessage.getNotification().getBody());
    }

    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        Log.e(TAG, "Data Payload: " + remoteMessage.getData().toString());

        try {
            JSONObject json = new JSONObject(remoteMessage.getData().toString());
            handleDataMessage(json);
        } catch (Exception e) {
            Log.e(TAG, "Exception: " + e.getMessage());
        }
    }
}

Android 清单 xml:

 <service
        android:name="notification.MyFirebaseMessagingService"
        android:exported="true">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
    <service android:name="notification.MyFirebaseInstanceIDService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>

如果是 vivo、oppo,我没有收到消息,建议您提供任何帮助。


Infinix Note 5 (Android One- Oreo) 和 Oppo F9(Oreo) 未获取 如果应用程序被杀死,则推送通知,如果应用程序处于运行状态,它们可以正常工作 背景或前景。

使用中国 ROM(Oxygen OS、MIUI 等),当从最近的应用程序托盘中滑动应用程序时,您的应用程序将被终止(类似于强制停止)。由于这个原因,每一个在后台运行的任务(比如服务)都会被应用程序杀死。即使是高优先级 FCM 在中文 ROM 中也不见踪影

实时问题:

1)您无法获取用户的位置。因此,如果依赖于实时位置,任何应用程序都无法正常运行

2) 您无法接收FCM高优先级通知

3)如果应用程序不在托盘中,则不会执行特定时间的任务/作业等等……。

Solution

用户需要在应用程序的设置中启用自动启动,以保持后台服务/作业运行。默认情况下它是关闭的。要在我们可以使用的某些设备中执行此操作,

示例代码

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent intent = new Intent();

    String manufacturer = android.os.Build.MANUFACTURER;

    switch (manufacturer) {

        case "xiaomi":
            intent.setComponent(new ComponentName("com.miui.securitycenter",
                    "com.miui.permcenter.autostart.AutoStartManagementActivity"));
            break;
        case "oppo":
            intent.setComponent(new ComponentName("com.coloros.safecenter",
                    "com.coloros.safecenter.permission.startup.StartupAppListActivity"));

            break;
        case "vivo":
            intent.setComponent(new ComponentName("com.vivo.permissionmanager",
                    "com.vivo.permissionmanager.activity.BgStartUpManagerActivity"));
            break;
    }

  List<ResolveInfo> arrayList =  getPackageManager().queryIntentActivities(intent,
          PackageManager.MATCH_DEFAULT_ONLY);

    if (arrayList.size() > 0) {
        startActivity(intent);
    }
}

}

来源:https://stackoverflow.com/questions/52849445/some-oreo-devices-are-not-getting-push-notification/52943903#52943903 https://stackoverflow.com/questions/52849445/some-oreo-devices-are-not-getting-push-notification/52943903#52943903

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

android fcm 中未出现 oppo、vivo 应用程序终止通知 的相关文章

随机推荐