一些Oreo设备没有获得推送通知

Tah*_*ani 13 performance android firebase firebase-cloud-messaging android-push-notification

三星S8/S5/J2/Note3正在Firebase Push Notification成功应用程序被杀死,在后台或前台,

Infinix Note 5 (Android One- Oreo)Oppo F9(Oreo)如果应用程序被杀害没有得到推送通知,他们的工作很好,如果应用程序在背景或前景.

我经历了很多文章,这个这个,提到中国手机有这个问题,并且用户方面有一些工作来使这些通知在他们的手机上工作.

但我想知道从开发方面是否有可能在每个Android设备上进行通知工作.

我的目标是API 27,这是我的代码

public class FirebaseMessagingService  extends com.google.firebase.messaging.FirebaseMessagingService {


  @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        String from = remoteMessage.getFrom();
        Map data = remoteMessage.getData();

        JSONObject jsonObject = new JSONObject();
        Set<String> keys = remoteMessage.getData().keySet();
        for (String key : keys) {
            try {
                jsonObject.put(key, remoteMessage.getData().get(key));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        message= jsonObject.getString("message");

         sendNotification(message, urlToOpen);



    private void sendNotification(final String msg, final String urlToOpen) {


        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                PendingIntent.FLAG_ONE_SHOT);

        String channelId = getString(R.string.notification_channel_general);
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(this, channelId)
                        .setSmallIcon(R.drawable.notification_icon)
                        .setContentTitle("App Name")
                        .setContentText(msg)
                        .setAutoCancel(true)
                        .setSound(defaultSoundUri)
                        .setPriority(Notification.PRIORITY_MAX)
                        .setContentIntent(pendingIntent);

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);


        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel(channelId,
                    "App Channel",
                    NotificationManager.IMPORTANCE_HIGH);
            notificationManager.createNotificationChannel(channel);
        }

    notificationManager.notify(0, notificationBuilder.build());
Run Code Online (Sandbox Code Playgroud)

摇篮

compileSdkVersion 27
defaultConfig {
    applicationId "com.myapp.app"
    minSdkVersion 19
    targetSdkVersion 27
    versionCode 2
    versionName "1"
    multiDexEnabled true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    vectorDrawables.useSupportLibrary = true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
        // Disable fabric build ID generation for debug builds
        ext.enableCrashlytics = false
    }
}

implementation 'com.google.firebase:firebase-messaging:15.0.0'
implementation 'com.google.android.gms:play-services-location:15.0.0'
implementation 'com.google.android.gms:play-services-auth:15.0.0'
implementation 'com.google.android.gms:play-services-basement:16.0.1'
implementation 'com.google.android.gms:play-services-ads-identifier:16.0.0'
implementation 'com.google.android.gms:play-services-stats:16.0.1'
implementation 'com.google.android.gms:play-services-tasks:16.0.1'
implementation 'com.google.android.gms:play-services-ads-identifier:16.0.0'
implementation 'com.google.android.gms:play-services-ads-identifier:16.0.0'
implementation 'com.google.android.gms:play-services-maps:16.0.0'
Run Code Online (Sandbox Code Playgroud)

Nil*_*hod 11

来源:在中文ROM中启用后台服务和作业(或FCM)

如果app被杀,Infinix Note 5(Android One-Oreo)和Oppo F9(Oreo)没有得到推送通知,如果应用程序处于后台或前台,它们可以正常工作.

当应用程序从最近的应用程序托盘中刷过你的应用程序终止时,中文ROM使用(氧气操作系统,MIUI等)(类似于强制停止).由于每个任务在后台运行,如服务,乔布斯被应用程序杀死.即便是高优先级的FCM也看不到中文ROM的日光

实时问题:

1)您无法获取用户的位置.因此,如果取决于实时位置,任何应用都无法正常工作

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

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

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

示例代码

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);
        }
    }

}
Run Code Online (Sandbox Code Playgroud)


K K*_*K K 6

在奥利奥,他们引入了推送通知信道化的一个新概念.您可以在此处详细了解渠道化.分别实施奥利奥及以下矿石的通知.您可以参考以下答案来解决问题.

我已经修复了xamarin.android中的问题,希望这对你有用.


nit*_*h29 5

这是所有中国设备的问题。一旦你杀死了应用程序......它会从内存中删除而不是所有活动......但对于其他设备制造商来说情况并非如此......他们不会删除该应用程序完全来自内存。我也遇到了小米设备的这个问题......他们可以选择锁定应用程序,即使应用程序被杀死以清除内存,也可以将应用程序保留在内存中


归档时间:

查看次数:

5299 次

最近记录:

6 年,7 月 前