1

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

3 Answers 3

2

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"} } } } 
Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

I also didn't find any solution. Please tell me if u know and also tell about infinix mobiles
0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.