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

android– 一些Oreo设备没有获得推送通知,第1张

概述三星S8/S5/J2/Note3成功获得Firebase推送通知应用程序被杀死,在后台或前台,但如果应用程序被杀,InfinixNote5(AndroidOne-Oreo)和OppoF9(Oreo)没有得到推送通知,如果应用程序处于后台或前台,它们可以正常工作.我经历了很多文章,this和this,提到中国手机存在这个问题,并

三星S8 / S5 / J2 / Note3成功获得Firebase推送通知应用程序被杀死,在后台或前台,

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

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

但我想知道从开发方面是否有可能在每个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());

摇篮

compileSdkVersion 27defaultConfig {    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'

解决方法:

资料来源:Enable background services and Jobs (or FCM) in Chinese ROMs

Infinix Note 5 (AndroID One- Oreo) and Oppo F9(Oreo) are not getting push notification if app is killed, they work fine if app is in background or foreground.

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

Real time problems :

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

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

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

Solution

用户需要在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);        }    }}
总结

以上是内存溢出为你收集整理的android – 一些Oreo设备没有获得推送通知全部内容,希望文章能够帮你解决android – 一些Oreo设备没有获得推送通知所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1102186.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存