Android的棉花糖请求许可? [英] Android marshmallow request permission?

查看:193
本文介绍了Android的棉花糖请求许可?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作的,需要几个危险权限的应用程序。所以,我想加入请求许可,需要在Android的男,但无法找到如何做到这一点。

I am currently working on an application that requires several "dangerous" permissions. So I tried adding "ask for permission" as required in Android M, but couldn't find how to do it.

我怎么能要求允许在我的应用程序中使用新的许可模式?

How can I ask for permission using new permission model in my app?

推荐答案

Android的-M即API 23推出<一href="http://developer.android.com/intl/es/about/versions/marshmallow/android-6.0-changes.html#behavior-runtime-permissions"相对=nofollow>运行权限以减少Android设备,用户现在可以直接在runtime.so管理应用程序权限的安全漏洞,如果用户通过询问拒绝您的应用程序,你必须获得其特定权限您在查询中提到的权限对话框。

Android-M ie, API 23 introduced Runtime Permissions for reducing security flaws in android device, where users can now directly manage app permissions at runtime.so if the user denies a particular permission of your application you have to obtain it by asking the permission dialog that you mentioned in your query.

行动之前,因此,检查,即检查是否有权限访问该资源的链接,如果​​你的应用程序没有,你可以请求许可的链接和处理类似下面的权限请求响应。

So check before action ie, check you have permission to access the resource link and if your application doesn't have that particular permission you can request the permission link and handle the the permissions request response like below.

@Override
public void onRequestPermissionsResult(int requestCode,
        String permissions[], int[] grantResults) {
    switch (requestCode) {
        case MY_PERMISSIONS_REQUEST_READ_CONTACTS: {
            // If request is cancelled, the result arrays are empty.
            if (grantResults.length > 0
                && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                // permission was granted, yay! Do the
                // contacts-related task you need to do.

               } else {

                // permission denied, boo! Disable the
                // functionality that depends on this permission.
            }
            return;
        }

        // other 'case' lines to check for other
        // permissions this app might request
    }
}

因此​​,最后,这是一个很好的做法,通过<一个href="http://developer.android.com/intl/es/about/versions/marshmallow/android-6.0-changes.html#behavior-runtime-permissions"相对=nofollow>行为更改如果您打算在新版本以避免武力上班关闭:)

So finally, It's a good practice to go through behavior changes if you are planning to work with new versions to avoid force closes :)

权限的最佳实践。

您可以下载官方的示例应用程序这里

You can download official sample app here.

这篇关于Android的棉花糖请求许可?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆