Android13-访问PDF或其他类型文件的权限
创始人
2024-09-30 23:00:53
0

为应用添加文件读取权限。具体代码示例如下:

在AndroidManifest.xml文件中添加以下权限:


在Java代码中获取Read External Storage权限:

if (ContextCompat.checkSelfPermission(thisActivity,
                Manifest.permission.READ_EXTERNAL_STORAGE)
        != PackageManager.PERMISSION_GRANTED) {

    // Permission is not granted
    // Should we show an explanation?
    if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
            Manifest.permission.READ_EXTERNAL_STORAGE)) {
        // Show an explanation 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; request the permission
        ActivityCompat.requestPermissions(thisActivity,
                new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);

        // MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE is an
        // app-defined int constant. The callback method gets the
        // result of the request.
    }
} else {
    // Permission has already been granted
}

在回调方法中处理权限请求的结果:

@Override
public void onRequestPermissionsResult(int requestCode,
        String[] permissions, int[] grantResults) {
    switch (requestCode) {
        case MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE: {
            // 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.
    }
}

相关内容

热门资讯

德州之星外挂!wpk微扑克真的... 德州之星外挂!wpk微扑克真的有辅助(透视)从前是真的有挂(详细辅助黑科技教程)1、不需要AI权限,...
透视实锤!wpk辅助器安装,w... 透视实锤!wpk辅助器安装,wpk俱乐部是做什么的(详细辅助透明挂教程)1、wpk辅助器安装系统规律...
WePoKe透明挂!wpk微扑... WePoKe透明挂!wpk微扑克辅助ai(透视)其实有挂(详细辅助wepoke教程)(1)WePoK...
透视神器!wpk透视辅助靠谱吗... 透视神器!wpk透视辅助靠谱吗,wepoker国外版透视(详细辅助AI教程)1、这是跨平台的wpk透...
wepoke有挂!nzt德州辅... wepoke有挂!nzt德州辅助(透视)一直存在有挂(详细辅助专业教程)1、金币登录送、破产送、升级...
透视插件!wepoker透视脚... 透视插件!wepoker透视脚本网页,wepoker免费辅助器(详细辅助透牌教程)1、金币登录送、破...
微扑克游戏辅助器!红龙扑克模拟... 微扑克游戏辅助器!红龙扑克模拟器(透视)原生真的是有挂(详细辅助技巧教程)(1)微扑克游戏辅助器!红...
透视攻略!wpk辅助插件,we... 透视攻略!wpk辅助插件,wepoker轻量版透视(详细辅助2025新版教程);在进入wpk辅助插件...
wepoke辅助有挂!aa p... 您好,wepoke辅助有挂这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩...
透视挂!智星德州菠萝安装,we... 透视挂!智星德州菠萝安装,wepoker辅助软件视频(详细辅助详细教程);1、玩家可以在智星德州菠萝...