gpt4 book ai didi

java - 某些设备(如 oppo、vivo、MI 等)的前台服务在 Doze 模式下被杀死

转载 作者:行者123 更新时间:2023-11-29 18:32:30 26 4
gpt4 key购买 nike

我正在使用前台服务来跟踪用户的实时位置。它在现有的 android 设备上运行良好,但在 oppo、vivo、Mi 等品牌中,当设备进入 hibernate 模式时,该应用程序被终止。我也尝试使用 FCM 通知仍然没有用。我只是想知道 Uber 或 Ola 是否能够解决这个问题,因为我看到大多数司机都在使用这些品牌。如何让他们的应用在 hibernate 模式下保持活跃?

最佳答案

you need enable auto start permission for apps in oppo , vivo and mi

try below code worked for me

 private void keepServicesInChineseDevices() {
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) {
AppDataHolder.getSession(MyApplication.getAppContext()).setPermissionForChineseDevices(true);
startActivity(intent);
}
}

this article is also helpful

关于java - 某些设备(如 oppo、vivo、MI 等)的前台服务在 Doze 模式下被杀死,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55652443/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com