简体   繁体   English

在China Phone中刷新应用程序后台服务已停止

[英]Application background service stopped when swiped up in China Phone

I have been searching for answers regarding this problem with China phone (Oppo, Huawei, XiaoMi, Vivo, etc.) when app is swiped up (close), the background services stopped running. 当应用程序被刷上(关闭),后台服务停止运行时,我一直在寻找有关中国手机(Oppo,华为,小米,Vivo等)此问题的答案。

Most of the solutions were: 大多数解决方案是:

  1. Include START_STICKY and use AlarmManager to start service. 包括START_STICKY并使用AlarmManager启动服务。
  2. Programmatically direct user to auto-start manager to enable app by user. 以编程方式将用户引导至自动启动管理器以按用户启用应用程序。
  3. Manually exclude my app from power saving mode or include my app as protected apps. 手动将我的应用从省电模式中排除,或将我的应用包含在受保护的应用中。

My question is how does apps like Whatsapp still receives message or notification even swiped up? 我的问题是像Whatsapp这样的应用程序如何仍然收到消息或通知甚至刷过? Furthermore, the solutions mentioned in 1. and 2. doesn't work if phone restarts, but how Whatsapp still can receive messages? 此外,如果手机重启,1和2中提到的解决方案不起作用,但Whatsapp如何仍能接收消息? I have tested Samsung devices, they have no problem running background services even though the app is swiped up. 我测试了三星设备,即使应用程序被刷了,他们也可以运行后台服务。 Has anyone face the same problem with China phone? 有没有人面对中国手机的同样问题?

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 ("oneplus".equalsIgnoreCase(manufacturer)) {
                intent.setComponent(new ComponentName("com.oneplus.security", "com.oneplus.security.chainlaunch.view.ChainLaunchAppListAct‌​ivity"));
            } 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"));
            }
            else if ("huawei".equalsIgnoreCase(manufacturer)) {
                intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
            }
            else if ("asus".equalsIgnoreCase(manufacturer)) {
                intent.setComponent(new ComponentName("com.asus.mobilemanager","com.asus.mobilemanager.autostart.AutoStartActivity"));
            }
            else {
                Log.e("other phone ", "===>");
            }
            List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
            if (list.size() > 0) {
                startActivity(intent);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

I am still looking for the answer. 我仍在寻找答案。 I have contacted Google support team and they replied as follow: 我已与Google支持小组联系,他们回复如下:

Upon discussion with our engineers, this is really the expected behavior. 在与我们的工程师讨论后,这确实是预期的行为。 For the reason that they use a stock ROM that disables the re-starting of background services for most apps. 因为他们使用了一个库存ROM来禁用重新启动大多数应用程序的后台服务。 Users should manually enable the auto-starting of background services as they are disabled by default. 用户应手动启用后台服务的自动启动,因为它们在默认情况下处于禁用状态。 This can not be programmatically enabled for all devices. 无法以编程方式为所有设备启用此功能。 So you'll have to prompt your users to perform the steps manually. 因此,您必须提示用户手动执行这些步骤。 Please check out this guide to learn more about this workaround. 请查看本指南以了解有关此变通方法的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM