本文介绍了对低端设备使用android 6.0 api 23权限(几乎与api 22一样)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的第一个问题,也许我会解释一点不好,但是好吧:我有一个使用api 22库的项目,但是使用android 6.0(api 23)进行编译,并且我想继续使用api 22库,但是当我使用android 6.0设备运行我的项目时,权限存在问题.../p>

我的问题:有没有一种方法可以在例如Android 5.1.1中工作,并且可以使用具有必要权限方法的Android 6.0进行编译?我的意思是,我可以添加一些库以供使用onRequestPermissionsResult(...)之类的回调吗?我尝试将api 23库添加到我的项目中,但没有使用他的方法,有什么建议... ??

解决方案

1.在此页面上查看您是否需要的许可是危险的许可 a>.

2.在如下所示的String数组中列出所需的所有危险权限.

private static final String[] REQUIRED_PERMISSIONS = new String[]{your_permissions_here};

3.将以下代码添加到您的onCreate().

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    LinkedList<String> missingPermissions = new LinkedList<>();
    for(String p : REQUIRED_PERMISSIONS){
        if(checkSelfPermission(p) != PackageManager.PERMISSION_GRANTED){
            missingPermissions.add(p);
        }
    }
    if(!missingPermissions.isEmpty()){
        String[] mpArray = new String[missingPermissions.size()];
        missingPermissions.toArray(mpArray);
        requestPermissions(mpArray, REQUEST_PERMISSIONS);
    }
}

REQUEST_PERMISSIONS是一个常数整数,用于标识此请求.

it's my first question here and maybe i'll explain a little bad, but okay look:I have a project with its using api 22 library, but compiles with android 6.0(api 23), and i wanna continue with api 22 library, but when i run my project with android 6.0 device i have problems with the permissions...

My question: is there a way that you can work in, for example, Android 5.1.1 and compile with Android 6.0 with the necessary permission's methods? i mean, can i add some library, for use callback like onRequestPermissionsResult(...) ? i tried adding api 23 library to my project but isnt works his methods, any suggestion...??

1. Checkout if the permission you need is a dangerous permission at this page.

2. List all dangerous permissions you need in a String array like below.

private static final String[] REQUIRED_PERMISSIONS = new String[]{your_permissions_here};

3. Add the following code to your onCreate().

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    LinkedList<String> missingPermissions = new LinkedList<>();
    for(String p : REQUIRED_PERMISSIONS){
        if(checkSelfPermission(p) != PackageManager.PERMISSION_GRANTED){
            missingPermissions.add(p);
        }
    }
    if(!missingPermissions.isEmpty()){
        String[] mpArray = new String[missingPermissions.size()];
        missingPermissions.toArray(mpArray);
        requestPermissions(mpArray, REQUEST_PERMISSIONS);
    }
}

REQUEST_PERMISSIONS is a constant integer to identify this requesting.

这篇关于对低端设备使用android 6.0 api 23权限(几乎与api 22一样)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 14:27