可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have a question regarding the new Android Marshmallow release:
Is it achievable to display the Permission Screen for a specific app via an Intent or something similar?

It's possible to display the app settings with the following code - is there an analog solution for directly opening the Permission Screen?
startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", getPackageName(), null)));
I already did some research on this but I wasn't able to find a proper solution - I would appreciate every help!
回答1:
According to the official Marshmallow permissions video (at the 4m 43s mark), you must open the application Settings page instead (from there it is one click to the Permissions page).
To open the settings page, you would do
Intent intent = new Intent(); intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts("package", getPackageName(), null); intent.setData(uri); startActivity(intent);
回答2:
This is not possible. I tried to do so, too. I could figure out the package name and the activity which will be started. But in the end you will get a security exception because of a missing permission you can't declare.
UPDATE:
Regarding the other answer I also recommend to open the App settings screen. I do this with the following code:
public static void startInstalledAppDetailsActivity(final Activity context) { if (context == null) { return; } final Intent i = new Intent(); i.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); i.addCategory(Intent.CATEGORY_DEFAULT); i.setData(Uri.parse("package:" + context.getPackageName())); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); context.startActivity(i); }
As I don't want to have this in my history stack I remove it using intent flags.
回答3:
Instead, you can open particular app's general settings with one line
startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:" + BuildConfig.APPLICATION_ID)));
回答4:
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Uri uri = Uri.fromParts("package", getPackageName(), null); intent.setData(uri); startActivity(intent);
Description
Settings.ACTION_APPLICATION_DETAILS_SETTINGS
Opens Details setting page for App. From here user have to manually assign desired permission.
Intent.FLAG_ACTIVITY_NEW_TASK
Optional. If set then opens Settings Screen(Activity) as new activity. Otherwise, it will be opened in currently running activity.
Uri.fromParts("package", getPackageName(), null)
Prepares or creates URI, whereas, getPackageName() - returns name of your application package.
intent.setData(uri)
Don't forget to set this. Otherwise, you will get android.content.ActivityNotFoundException. Because you have set your intent as Settings.ACTION_APPLICATION_DETAILS_SETTINGS and android expects some name to search.
回答5:
If we are talking about FLYME OS (Meizu) ONLY there are it's own Security app with permissions.
To open it use following intent:
public static void openFlymeSecurityApp(Activity context) { Intent intent = new Intent("com.meizu.safe.security.SHOW_APPSEC"); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.putExtra("packageName", BuildConfig.APPLICATION_ID); try { context.startActivity(intent); } catch (Exception e) { e.printStackTrace(); } }
Of-cause BuildConfig is your app's BuildConfig.