英文:
How to Enable Autostart option programmatically in Samsung devices?
问题
我正在使用后台服务,但在某些设备上无法运行,因为我必须为应用启用自启动权限。我想在需要时自动启用自启动权限。我正在使用这段代码,但它将我重定向到自启动权限窗口。但在三星手机上,它没有跳转到该窗口。
我想要解决方案适用于三星设备。
英文:
I am using the background services and it does not run on some devices as I have to enable the autostart permission for the app. I want to enable the autostart permission automatically where it needs. I am using this code but it redirects me on the window where the autostart permission is. But in samsung mobiles it is not directing to that window
if ("xiaomi".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
alertdialogue(intent);
} else if ("oppo".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity"));
alertdialogue(intent);
} else if ("vivo".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity"));
alertdialogue(intent);
} else if ("Letv".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.letv.android.letvsafe", "com.letv.android.letvsafe.AutobootManageActivity"));
alertdialogue(intent);
} else if ("Honor".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
alertdialogue(intent);
}
i want solution for samsung devices
答案1
得分: 2
以下是翻译好的部分:
"com.samsung.android.sm" 是在 N/7.0/24 及更高版本的包名,但我发现在 Q/10.0/29 上,活动名称已从 "com.samsung.android.sm.ui.battery.BatteryActivity" 更改为 "com.samsung.android.sm.battery.ui.BatteryActivity"。我不确定 O 或 P。最好的方法是简单地列出所有可能的解决方案,然后依次尝试它们:
fun openSamsungBackgroundSettings() {
val possibleIntents = mutableListOf<Intent>()
val battery1 = "com.samsung.android.sm.ui.battery.BatteryActivity"
val battery2 = "com.samsung.android.sm.battery.ui.BatteryActivity"
val pkg = if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N)
"com.samsung.android.lool"
else
"com.samsung.android.sm"
possibleIntents.add(Intent().setComponent(ComponentName(pkg, battery1)))
possibleIntents.add(Intent().setComponent(ComponentName(pkg, battery2)))
//general settings as backup
possibleIntents.add(Intent(Settings.ACTION_SETTINGS))
possibleIntents.forEach {
try {
startActivity(it)
return
} catch (ex: Exception) {
w(ex) { "Failed to open intent:$it" }
}
}
}
请注意,这是提供的代码的翻译部分。如果您需要更多帮助或有其他翻译请求,请随时告诉我。
英文:
The other answers are right in saying that com.samsung.android.sm
is the package name on N/7.0/24 and above, however I have found that on Q/10.0/29 the activity name has changed from com.samsung.android.sm.ui.battery.BatteryActivity
to com.samsung.android.sm.battery.ui.BatteryActivity
. I'm not sure about O or P. Best thing is to simply make a list of all the possible resolutions and try them in turn:
fun openSamsungBackgroundSettings() {
val possibleIntents = mutableListOf<Intent>()
val battery1 = "com.samsung.android.sm.ui.battery.BatteryActivity"
val battery2 = "com.samsung.android.sm.battery.ui.BatteryActivity"
val pkg = if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N)
"com.samsung.android.lool"
else
"com.samsung.android.sm"
possibleIntents.add(Intent().setComponent(ComponentName(pkg, battery1)))
possibleIntents.add(Intent().setComponent(ComponentName(pkg, battery2)))
//general settings as backup
possibleIntents.add(Intent(Settings.ACTION_SETTINGS))
possibleIntents.forEach {
try {
startActivity(it)
return
} catch (ex: Exception) {
w(ex){"Failed to open intent:$it"}
}
}
}
答案2
得分: 0
新的意图().setComponent(new ComponentName("com.samsung.android.lool","com.samsung.android.sm.ui.battery.BatteryActivity"))
尝试此意图,但这是用于跳转到电池优化控制活动的,找不到适用于三星的精确的AutoStart意图,如果您找到了,请告诉我。
英文:
new Intent().setComponent(new ComponentName("com.samsung.android.lool","com.samsung.android.sm.ui.battery.BatteryActivity"))
try this intent, but this is for taking to battery optimisation control activity,
didnt found exact AutoStart intend for Samsung, if you find then let me know please
答案3
得分: 0
有一些三星手机不支持此授权(没有电池优化活动),但对于那些支持的手机,有两种情况:
在Android L上,使用以下信息:
"com.samsung.android.sm", "com.samsung.android.sm.ui.battery.BatteryActivity"
在Android N上,使用以下信息:
"com.samsung.android.lool", "com.samsung.android.sm.ui.battery.BatteryActivity"
英文:
there is some Samsung mobile who don't support this authorization (dont have an activity for battery optimization)
however for those who have there is two case
"com.samsung.android.sm", "com.samsung.android.sm.ui.battery.BatteryActivity"
on Android L
"com.samsung.android.lool", "com.samsung.android.sm.ui.battery.BatteryActivity"
on Android N
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论