首页 > 其他分享 >android 文件访问权限处理

android 文件访问权限处理

时间:2022-08-15 10:56:39浏览次数:106  
标签:文件 Log buffer MANAGE 访问 new android 权限

对于/storage/emulated/0没没有权限访问的问题进行如下解决:

1、加入文件读写、和存储管理权限 READ_EXTERNAL_STORAGE  MANAGE_EXTERNAL_STORAGE  requestLegacyExternalStorage

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.helloworld">
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:requestLegacyExternalStorage="true"
        android:theme="@style/Theme.HelloWorld">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/Theme.HelloWorld.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

2、代码中动态获取

Intent intent = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
                    startActivity(intent);

3、读取相关文件

                try {

                    InputStream is = new FileInputStream(new File("/storage/emulated/0/Pictures/hello.txt"));
                        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
                    String buffer;
                    while ((buffer = bufferedReader.readLine()) != null) {
                        Log.i(TAG, "read line:" + buffer);
                    }
                } catch (Exception e) {
                    Log.i(TAG, "error msg:" + e.getMessage());
                }

 

标签:文件,Log,buffer,MANAGE,访问,new,android,权限
From: https://www.cnblogs.com/SaraMoring/p/16587445.html

相关文章

  • nginx 一些简单访问控制模块
    nginx已经内置了一些简单的访问控制模块,利用好这些模块我们可以提升系统的安全几个比较有用的标准模块基本都是利用了access阶段的能力limit_except限制请求方法的(......
  • Android自定义矩形View中任意拖动圆点获取色温值(RectangleWheel)
    如图所示:矩形色温条中,拖动圆点获取当前色温值  1、自定义属性res->values下创建attrs.xml文件<declare-styleablename="RectangleWheel"><!--矩形宽高......
  • Django设置跨域访问
    Django设置跨域访问(1)安装DjangoCorsHeaderspipinstalldjango-cors-headers(2)settings.py配置如下INSTALLED_APPS=[#'django.contrib.admin','d......
  • django restframework 后端接口权限
    REST_FRAMEWORK={'EXCEPTION_HANDLER':'djangoProject.utils.exception.custom_exception_handler',#在不需要权限就能访问的视图设置permissions_classes......
  • 01-Android平台的虚拟机是基于栈的吗?
    前言:这里打算开一个新的专栏,就是关于Android面试相关的一些知识点的学习,其实前几年已经有相关专栏了:只是未对外开放,我记得当时本来是开放着的,但是因为当时去某厂去面试......
  • [c++] windows下检查当前程序是不是以管理员权限运行
    很多程序运行的时候,一些操作需要管理员权限才能运行,正好微软提供了一个接口IsUserAnAdmin,可以让我们很方便的检测出当前程序是不是以admin运行的。#include<ShlObj.h>......
  • Android与iOS的区别
    最变成我最爱的一个问题,但一直没思考真正的回答思路是什么样的;面试者有提到,但不全面,特此整理。ps.80%面试者都会回答没什么区别…每次和他们聊都觉得是培训出来的;特别最......
  • cordova配置app开机自启动---测试通过于Android10.1.2
    本方法适用于AndroidPDA开发,通常AndroidPDA支持开放所用权限给使用者,因此PDA不会限制App开机自动运行。修改config.xml,添加监听开机启动的权限<platform name="an......
  • android系统
    前言详细记录一下android基础知识包括但不限于EDL(9008)bootloaderfastboot工具adb工具android分区···拓展boot分区损坏system分区损坏vendor分区......
  • Android开发 Direct local .aar file dependencies are not supported when building
    报错信息debug模式是好的,但是编译app时报错:Directlocal.aarfiledependenciesarenotsupportedwhenbuildinganAAR.TheresultingAARwouldbebroken......