美文网首页
【Android】权限申请的增加用户体验

【Android】权限申请的增加用户体验

作者: 李翾 | 来源:发表于2017-12-23 14:40 被阅读0次

    // Here, thisActivity is the current activity
    if (ContextCompat.checkSelfPermission(thisActivity,
    Manifest.permission.READ_CONTACTS)
    != PackageManager.PERMISSION_GRANTED) {

    // Should we show an explanation?
    if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
            Manifest.permission.READ_CONTACTS)) {
    

    这个方法,如果用户允许过,又把权限给关了,会返回true,这里可以处理给用户做解释

        // Show an expanation to the user *asynchronously* -- don't block
        // this thread waiting for the user's response! After the user
        // sees the explanation, try again to request the permission.
    
    } else {
    
        // No explanation needed, we can request the permission.
    
        ActivityCompat.requestPermissions(thisActivity,
                new String[]{Manifest.permission.READ_CONTACTS},
                MY_PERMISSIONS_REQUEST_READ_CONTACTS);
    
        // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
        // app-defined int constant. The callback method gets the
        // result of the request.
    }
    

    }

    相关文章

      网友评论

          本文标题:【Android】权限申请的增加用户体验

          本文链接:https://www.haomeiwen.com/subject/hzvfgxtx.html