几个月前我偶然发现了同样的问题。问题是所有流行的应用程序,如 WhatsApp 和 Skype,默认情况下都被小米允许,但不是你的应用程序。不知道后台到底在搞什么交易,但对开发者来说似乎是不公平的。
现在解决办法,这段代码会导致小米和其他手机品牌的权限设置,他们定制自己的ROM,为所欲为——
private void specialPermission() {
String alertMessage = "Please allow APP_NAME to always run in the background, else our services can't be accessed when you are in distress.";
final String brand = Build.BRAND;
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setMessage(alertMessage);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent();
if (brand.equalsIgnoreCase("xiaomi")) {
intent.setComponent(new ComponentName("com.miui.securitycenter",
"com.miui.permcenter.autostart.AutoStartManagementActivity"));
startActivity(intent);
} else if (brand.equalsIgnoreCase("Letv")) {
intent.setComponent(new ComponentName("com.letv.android.letvsafe",
"com.letv.android.letvsafe.AutobootManageActivity"));
startActivity(intent);
} else if (brand.equalsIgnoreCase("Honor")) {
intent.setComponent(new ComponentName("com.huawei.systemmanager",
"com.huawei.systemmanager.optimize.process.ProtectActivity"));
startActivity(intent);
} else if (Build.MANUFACTURER.equalsIgnoreCase("oppo")) {
try {
intent.setClassName("com.coloros.safecenter",
"com.coloros.safecenter.permission.startup.StartupAppListActivity");
startActivity(intent);
} catch (Exception e) {
try {
intent.setClassName("com.oppo.safe",
"com.oppo.safe.permission.startup.StartupAppListActivity");
startActivity(intent);
} catch (Exception ex) {
try {
intent.setClassName("com.coloros.safecenter",
"com.coloros.safecenter.startupapp.StartupAppListActivity");
startActivity(intent);
} catch (Exception exx) {
exx.printStackTrace();
}
}
}
} else if (Build.MANUFACTURER.contains("vivo")) {
try {
intent.setComponent(new ComponentName("com.iqoo.secure",
"com.iqoo.secure.ui.phoneoptimize.AddWhiteListActivity"));
startActivity(intent);
} catch (Exception e) {
try {
intent.setComponent(new ComponentName("com.vivo.permissionmanager",
"com.vivo.permissionmanager.activity.BgStartUpManagerActivity"));
startActivity(intent);
} catch (Exception ex) {
try {
intent.setClassName("com.iqoo.secure",
"com.iqoo.secure.ui.phoneoptimize.BgStartUpManager");
startActivity(intent);
} catch (Exception exx) {
ex.printStackTrace();
}
}
}
}
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
您所要做的就是显示一个对话框,描述您对后台服务的必要性并打开权限设置。即使它不是SWIPE KILL的完整修复程序,无论如何都会停止服务。