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

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

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

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

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

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


当前回答

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

其他回答

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

根据Android文档

试试这个

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

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

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

如果你想在Kotlin中写更少的代码,你可以这样做:

fun Context.openAppSystemSettings() {
    startActivity(Intent().apply {
        action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
        data = Uri.fromParts("package", packageName, null)
    })
}

根据Martin Konecny的回答

Kotlin风格。

startActivity(Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
    data = Uri.fromParts("package", packageName, null)
})