【问题标题】:unable to receive push notifications in few android phones无法在少数安卓手机中接收推送通知
【发布时间】:2018-11-26 17:15:46
【问题描述】:

当应用在 Oppo、华为、小米和 OnePlus 等某些设备上被终止时,我在接收 FCM 推送通知时遇到问题。我了解这是由于自定义 ROM 手机中的电池优化设置所致。如果手动开启设置,我可以接收通知。

但我想知道是否有办法以编程方式克服这个问题。有人做到了吗?

提前致谢!

【问题讨论】:

    标签: android


    【解决方案1】:

    很少有手机制造商不允许外部通知,直到 接收通知的权限集

    onTokenRefresh()内部调用这个方法

    private void addAutoStartup() {
        try {
            Intent intent = new Intent();
            String manufacturer = android.os.Build.MANUFACTURER;
            if ("xiaomi".equalsIgnoreCase(manufacturer)) {
                intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
            } else if ("oppo".equalsIgnoreCase(manufacturer)) {
                intent.setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity"));
            } else if ("vivo".equalsIgnoreCase(manufacturer)) {
                intent.setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity"));
            } else if ("Letv".equalsIgnoreCase(manufacturer)) {
                intent.setComponent(new ComponentName("com.letv.android.letvsafe", "com.letv.android.letvsafe.AutobootManageActivity"));
            } else if ("Honor".equalsIgnoreCase(manufacturer)) {
                intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
            }
            List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
            if  (list.size() > 0) {
                startActivity(intent);
            }
        } catch (Exception e) {
            Log.e(TAG , String.valueOf(e));
        }
    }
    

    【讨论】:

    • 感谢 Chethan,但这将再次需要用户操作才能将其打开。我已经添加了这个,但是电池优化会杀死它,我试图找出是否可以在没有用户操作的情况下以编程方式完成。
    • 请查看link。已经给出了一些解释。
    • 是的,这是事实。我明白,但许多应用程序都被列入白名单,我想知道是否有办法以编程方式进行
    猜你喜欢
    • 1970-01-01
    • 2021-08-08
    • 1970-01-01
    • 2012-12-24
    • 1970-01-01
    • 2017-12-01
    • 1970-01-01
    相关资源
    最近更新 更多