Skip to content Skip to sidebar Skip to footer

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 automatic

Solution 1:

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:

funopenSamsungBackgroundSettings() {

    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"}
        }
    }
}

Solution 2:

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

Solution 3:

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

Post a Comment for "How To Enable Autostart Option Programmatically In Samsung Devices?"