• Android 6.0的权限问题


    Android 6.0的权限获取不同于别的版本,具体的实例如下:

    if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS)
            != PackageManager.PERMISSION_GRANTED) {
        //申请READ_CONTACTS权限
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_CONTACTS},
                READ_CONTACTS_REQUEST_CODE);
    }
    
     
    
     
    
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        doNext(requestCode, grantResults);
    
    }
    
     
    
     
    
    private void doNext(int requestCode, int[] grantResults) {
        if (requestCode == READ_CONTACTS_REQUEST_CODE) {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                // Permission Granted
                LogUtils.i(TAG,"获取了读取通讯录的权限");
                creditCheckTask.getAndSendContact();
            } else {
                LogUtils.i(TAG,"没有获取读取通讯录权限");
                // Permission Denied
                return;
            }
        }
    
    }
     
     
     
     
  • 相关阅读:
    Codeforces Round #564 (Div. 1)
    Codeforces Round #569 (Div. 1)
    SDOI2019R2游记
    BZOJ 3555: [Ctsc2014]企鹅QQ
    SDOI2019R1游记
    计数的一些东西
    多项式的各种操作
    BZOJ 5424: 烧桥计划
    Codeforces Round #545 (Div. 1)
    概率期望学习笔记
  • 原文地址:https://www.cnblogs.com/beigongfengchen/p/5583278.html
Copyright © 2020-2023  润新知