手机锁定后,华为会杀死后台应用 [英] HUAWEI kill a background app when the phone is locked
问题描述
这是我第一次在此论坛上提问:p 我制作了一个必须在后台运行的android应用程序,即当手机处于待机状态时才能恢复用户的位置.我使用服务和唤醒锁. 该应用程序可以在 SAMSUNG 上运行,但是我注意到 HUAWEI 将杀死该应用程序(如果它不在受保护的应用程序列表中). 因此,我创建了一个对话框,告诉用户激活受保护应用程序列表中的应用程序,如下所示:
this is the first time I ask a question on this forum: p I made an android application that must work in the background ie when the phone is on standby to be able to recover the location of the user. I use a service and wakelock. The application works on SAMSUNG but I noticed that HUAWEI kills the application if it is not in the list of protected applications. So I create a dialog box to tell the user to activate the application in the list of protected applications as shown here: Keeping a periodic service active while the phone is locked Since my app should run on all android phones I will want to know if there are other phones brands that kill the app when the phone is idle to do the same thing please. Thank you in advance :)
推荐答案
我遇到了同样的问题,并且使用可访问性,我试图让类名或活动名传递意图并打开设置,看起来像旧的受保护的应用列表不再可用,一种新方法是:
I was facing the same problem and using accessibility I tried to get the class name or activity name to pass in intent and open the settings and looks like Old Protected app list is no more available, a new way is:
在华为启动中禁用该应用程序
disable the application from Launch in HUAWEI
在Oreo Huawei p10上测试:
tested on Oreo Huawei p10:
对于手动",您可以执行以下步骤:
For Manually you can go with below steps:
设置->电池->启动
找到您的应用程序并禁用
and find your application and disable
以编程方式:
public class Constant {
public static List<Intent> POWERMANAGER_INTENTS = Arrays.asList(
new Intent().setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity")),
new Intent().setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity")),
new Intent().setComponent(new ComponentName("com.letv.android.letvsafe", "com.letv.android.letvsafe.AutobootManageActivity")),
new Intent().setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity")),
new Intent().setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.startupapp.StartupAppListActivity")),
new Intent().setComponent(new ComponentName("com.oppo.safe", "com.oppo.safe.permission.startup.StartupAppListActivity")),
new Intent().setComponent(new ComponentName("com.iqoo.secure", "com.iqoo.secure.ui.phoneoptimize.AddWhiteListActivity")),
new Intent().setComponent(new ComponentName("com.iqoo.secure", "com.iqoo.secure.ui.phoneoptimize.BgStartUpManager")),
new Intent().setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity")),
new Intent().setComponent(new ComponentName("com.asus.mobilemanager", "com.asus.mobilemanager.entry.FunctionActivity")).setData(android.net.Uri.parse("mobilemanager://function/entry/AutoStart"))
);
}
在实用程序或活动类中放置以下代码
Put below code in Your Util or Activity Class
private static boolean isCallable(Context context, Intent intent) {
List<ResolveInfo>list=context.getPackageManager().queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
saveUserSessionManager是首选项,您可以设置首选项类而不是SaveUserSessionManager
saveUserSessionManager is a Preference, you can set your preference class instead of SaveUserSessionManager
public static void startPowerSaverIntent(Context context, SaveUserSessionManager saveUserSessionManager) {
boolean skipMessage = saveUserSessionManager.getDataByKey("skipProtectedAppCheck", false);
if (!skipMessage) {
boolean foundCorrectIntent = false;
for (Intent intent : Constant.POWERMANAGER_INTENTS) {
if (isCallable(context, intent)) {
foundCorrectIntent = true;
new AlertDialog.Builder(context)
.setTitle(Build.MANUFACTURER + " Protected Apps")
.setMessage(String.format("%s requires to be 'White list' to function properly.\nDisable %s from list.%n", context.getString(R.string.app_name), context.getString(R.string.app_name)))
.setPositiveButton("Go to settings", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
context.startActivity(intent);
saveUserSessionManager.storeDataByKey("skipProtectedAppCheck", true);
dialog.dismiss();
}
})
.show();
break;
}
}
}
}
如何拨打电话? 在您的MainActivity中的onResume方法中,检查其启用情况.
How To call? In your MainActivity in onResume method check its enable or not.
@Override
protected void onResume() {
super.onResume();
//saveUserSessionManager is just a Preference you can set your preference class instead of SessionManager
if (!saveUserSessionManager.getDataByKey("skipProtectedAppCheck", false)) {
Utils.startPowerSaverIntent(mContext, saveUserSessionManager);
}
}
仅此而已:)
这篇关于手机锁定后,华为会杀死后台应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!