如何在三星设备上以编程方式启用自动启动选项?

huangapple go评论109阅读模式
英文:

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&lt;Intent&gt;()
	val battery1 = &quot;com.samsung.android.sm.ui.battery.BatteryActivity&quot;
	val battery2 = &quot;com.samsung.android.sm.battery.ui.BatteryActivity&quot;
	val pkg = if (Build.VERSION.SDK_INT &gt; Build.VERSION_CODES.N)
		&quot;com.samsung.android.lool&quot;
	else
		&quot;com.samsung.android.sm&quot;
	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){&quot;Failed to open intent:$it&quot;}
		}
	}
}

答案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

&quot;com.samsung.android.sm&quot;, &quot;com.samsung.android.sm.ui.battery.BatteryActivity&quot; on Android L

&quot;com.samsung.android.lool&quot;, &quot;com.samsung.android.sm.ui.battery.BatteryActivity&quot; on Android N

huangapple
  • 本文由 发表于 2020年1月6日 15:01:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/59607933.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定