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.
    }
}

相关内容

热门资讯

2分钟辅助!创思维激k有挂吗,... 【亲,创思维激k有挂吗 这款游戏可以开挂的,确实是有挂的,很多玩家在这款创思维激k有挂吗中打牌都会发...
第十分钟辅助!wepoker亲... 第十分钟辅助!wepoker亲友圈有用吗,丹东约战麻将辅助器(一分钟了解开挂辅助脚本);亲真的是有正...
6分钟开挂!wepoker透视... 6分钟开挂!wepoker透视脚本下载,闲逸辅助脚本(透视透视开挂辅助神器);无需打开直接搜索微信(...
5分钟辅助!皮皮胡子辅助,潮友... 5分钟辅助!皮皮胡子辅助,潮友会虾蟹骰子概率计算方式(玩家必看开挂辅助安装);潮友会虾蟹骰子概率计算...
1分钟辅助!微信微乐有挂没有,... 1分钟辅助!微信微乐有挂没有,微信中至有辅助吗(透视有挂开挂辅助平台);相信小伙伴都知道这个微信中至...
第1分钟辅助!禅游游戏辅助,乐... 第1分钟辅助!禅游游戏辅助,乐平包王攻略(科普常识开挂辅助平台);大家肯定在之前乐平包王攻略或者乐平...
第9分钟开挂!广西微乐小程序脚... 第9分钟开挂!广西微乐小程序脚本,河洛杠次插件(最新技巧开挂辅助下载)【无需打开直接搜索加薇1367...
第4分钟辅助!贪玩互娱辅助,微... 第4分钟辅助!贪玩互娱辅助,微乐小程序挂哪里有(今日重大通报开挂辅助工具);相信小伙伴都知道这个微乐...
第七分钟开挂!欢聚水鱼天下辅助... 您好:这款欢聚水鱼天下辅助游戏是可以开挂的,确实是有挂的,很多玩家在这款欢聚水鱼天下辅助游戏中打牌都...
第四分钟辅助!xpoker透视... 第四分钟辅助!xpoker透视辅助,小闲川南手游辅助器(技巧知识分享开挂辅助安装);小薇(透视辅助)...