如何以编程方式在小米中为应用程序启用自动启动 [英] How to enable auto start for an app in xiaomi programmatically
本文介绍了如何以编程方式在小米中为应用程序启用自动启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道小米是否可以为任何应用程序提供后台服务? 我的应用程序中有服务,该服务需要一直在后台运行,在所有设备上,除小米外,其他设备都可以正常工作.
I would like to know whether the background service for any application can be provided by xiaomi? I have service in my app which need to be running in background all the time , in all devices its working fine except Xiaomi, how it can be done programmatically?
推荐答案
适用于小米,oppo,vivo和oneplus手机.
Works for xiaomi, oppo, vivo and oneplus phones as well.
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.ChainLaunchAppListActivity")); }
List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() > 0) {
context.startActivity(intent);
}
} catch (Exception e) {
Crashlytics.logException(e);
}
这篇关于如何以编程方式在小米中为应用程序启用自动启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文