如何以编程方式打开Android棉花糖上特定应用的权限屏幕?

本文翻译自:How to programmatically open the Permission Screen for a specific app on Android Marshmallow?

I have a question regarding the new Android Marshmallow release: 我对新的Android Marshmallow版本有疑问:

Is it achievable to display the Permission Screen for a specific app via an Intent or something similar? 是否可以通过Intent或类似方法显示特定应用程序的权限屏幕?

Android M权限屏幕

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楼

参考:https://stackoom.com/question/2DiWj/如何以编程方式打开Android棉花糖上特定应用的权限屏幕


#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楼

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). 根据官方的棉花糖权限视频(在4m 43s标记处 ),您必须改为打开应用程序的“设置”页面(从那里一键单击到“权限”页面)。

To open the settings page, you would do 要打开设置页面,您需要执行

Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
startActivity(intent);

#4楼

It's possible with requestPermissions method 使用requestPermissions方法是可能的

Though you can't directly see the setting page, you can change the access permissions. 虽然您无法直接看到设置页面,但您可以更改访问权限。
A good example: 一个很好的例子:
https://www.learn2crack.com/2015/10/android-marshmallow-permissions.html https://www.learn2crack.com/2015/10/android-marshmallow-permissions.html

This way you can check and call 这样你就可以查看并致电

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && 
   checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)
{

                requestPermissions(new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE}, 0);

}

#5楼

it is not possible to pragmatically get the permission... but ill suggest you to put that line of code in try{} catch{} which make your app unfortunately stop... and in catch body make a dialog box which will navigate the user to small tutorial to enable the draw over other apps permission... then on yes button click put this code... 务实地获得许可是不可能的...但是生病的建议您将这段代码放入try {} catch {}中,这会使您的应用程序不幸停止...并在catch主体中创建一个对话框,该对话框将导航到用户进入小型教程,以启用覆盖其他应用程序的权限...然后在“是”按钮上,单击将此代码放置...

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

this intent is to directly open the list of draw over other apps to manage permissions and then from here it is one click to the draw over other apps Permissions ... i know this is Not the answer you're looking for... but Im doing this in my apps... 目的是直接打开其他应用程序的绘制列表以管理权限,然后从此处单击以绘制其他应用程序的权限...我知道这不是您要查找的答案...但是我在我的应用程序中这样做...


#6楼

相反,您可以只一行打开特定应用的常规设置

 startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:" + BuildConfig.APPLICATION_ID)));
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值