How to go Auto start permission page in Honor 10 Lite?

Viewed 133

In my app, i want to enable auto start when user is logging into app. So i am using like below

val powerManagerIntent = arrayOf(

Intent().setComponent(
    ComponentName(
        "com.huawei.systemmanager",
        "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity"
    )
),
Intent().setComponent(
    ComponentName(
        "com.huawei.systemmanager",
        "com.huawei.systemmanager.optimize.process.ProtectActivity"
    )
),
Intent().setComponent(
    ComponentName(
        "com.huawei.systemmanager",
        "com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity"
    )
)
)

And

 for (intent in Utils.powerManagerIntent) if (packageManager.resolveActivity(
                intent,
                PackageManager.MATCH_DEFAULT_ONLY
            ) != null
        ) {
MaterialAlertDialogBuilder(
this@StartChildModeActivity,
R.style.MyThemeOverlay_MaterialComponents_MaterialAlertDialog)
.setTitle("Enable AutoStart")
.setMessage("Please allow AppName to always run in the background,else our services can't be accessed.")
.setCancelable(false)
.setNegativeButton(resources.getString(R.string.btn_cancel)) { dialog, _ ->
    dialog.dismiss()
}
.setPositiveButton("ALLOW") { dialog, _ ->
}.show()
}

Huawei device is working fine and honor is crashing when trying this. Any help is much appreciated

1 Answers

Please use the below 2 intent components:

val powerManagerIntent = arrayOf(
    Intent().setComponent(
        ComponentName(
            "com.huawei.systemmanager",
            "com.huawei.systemmanager.optimize.process.ProtectActivity"
        )
    ),
    Intent().setComponent(
        ComponentName(
            "com.huawei.systemmanager",
            "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity"
        )
    ),
    )

Also, please try to add the below permission in AndroidManifest.xml:

<uses-permission android:name="com.huawei.permission.external_app_settings.USE_COMPONENT"/>
Related