首页 > 解决方案 > 如何进入荣耀10 Lite的自动启动权限页面?

问题描述

在我的应用程序中,我想在用户登录应用程序时启用自动启动。所以我使用如下

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

 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()
}

华为设备工作正常,尝试此操作时荣誉崩溃。任何帮助深表感谢

标签: androidkotlinhuawei-mobile-servicesautostarthuawei-developers

解决方案


请使用以下 2 个意图组件:

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"
        )
    ),
    )

另外,请尝试在 AndroidManifest.xml 中添加以下权限:

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

推荐阅读