我有一个关于新的Android 6.0 (Marshmallow)发布的问题。

是否有可能通过Intent或类似的东西来显示特定应用程序的“应用程序权限”屏幕?

使用以下代码可以在设置中显示应用程序的“应用程序信息”屏幕:

startActivity(
    new Intent(
        android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
        Uri.fromParts("package", getPackageName(), null)
    )
);

是否有类似的解决方案直接打开应用程序的“应用程序权限”屏幕?

我已经对此做了一些研究,但我无法找到解决方案。


当前回答

从Android 11开始,你可以直接打开特定于应用程序的位置权限设置页面,只使用这样的代码:

然而,上述方法只会有效一次。如果用户拒绝许可,甚至不小心关闭了屏幕,应用程序永远不会触发它再次出现。

除此之外,答案与Android 11之前一样——你能做的最好的事情就是打开应用程序特定的设置页面,让用户手动下钻两层以启用适当的权限。

val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
val uri: Uri = Uri.fromParts("package", packageName, null)
intent.data = uri
// This will take the user to a page where they have to click twice to drill down to grant the permission
startActivity(intent)

请看我的相关问题:Android 11用户不能授予后台位置权限?

其他回答

Xamarin form Android:

//---------------------------------------------------------
public void OpenSettings()
//---------------------------------------------------------
{
    var intent = new Intent(Android.Provider.Settings.ActionApplicationDetailsSettings,
        Android.Net.Uri.Parse("package:" + Forms.Context.PackageName));
    Forms.Context.StartActivity(intent);
}

从实用主义的角度获得许可是不可能的。 但我建议你把这行代码放在try{} catch{}中,这会让你的应用不幸地停止…

在catch主体中,创建一个对话框,将用户导航到一个小教程,以启用其他应用程序的权限。 然后在确定按钮上单击添加此代码…

Intent callSettingIntent= new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
startActivity(callSettingIntent);

这一意图是直接打开其他应用程序的权限管理权限,然后从这里是一个点击到其他应用程序的权限。

我知道这不是你想要的答案……但我在我的应用程序中这样做…

打开特定应用程序的权限界面

            if (ContextCompat.checkSelfPermission(
                    context, Manifest.permission.WRITE_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED
            ) {
                //Permission is not granted yet. Ask for permission.
                val alertDialog = AlertDialog.Builder(context)
                alertDialog.setMessage(context.getString(R.string.file_permission))
                alertDialog.setPositiveButton("सेटिंग") { _, _ ->
                    val intent = Intent(
                        Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
                        Uri.fromParts("package", BuildConfig.APPLICATION_ID, null)
                    )
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                    context.startActivity(intent)
                }
                alertDialog.setNegativeButton("हाँ") { _, _ ->
                    ActivityCompat.requestPermissions(
                        context as Activity, arrayOf(
                            Manifest.permission.WRITE_EXTERNAL_STORAGE
                        ), 1
                    )
                }
                alertDialog.show()
            } else {}

不可能以编程方式打开权限屏幕。相反,我们可以打开应用程序设置屏幕。

Code

Intent i = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:" + BuildConfig.APPLICATION_ID));
startActivity(i);

样例输出

根据Android文档

试试这个

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName(appDetails.packageName,"com.android.packageinstaller.permission.ui.ManagePermissionsActivity"));
startActivity(intent);