Android 11 之后
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
这两个没啥用了,不起作用
需要新的动态获取权限的方法
先声明
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
然后再动态调用
private void requestmanageexternalstorage_Permission() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { // 先判断有没有权限 if (Environment.isExternalStorageManager()) { Toast.makeText(this, "Android VERSION R OR ABOVE,HAVE MANAGE_EXTERNAL_STORAGE GRANTED!", Toast.LENGTH_LONG).show(); } else { Toast.makeText(this, "Android VERSION R OR ABOVE,NO MANAGE_EXTERNAL_STORAGE GRANTED!", Toast.LENGTH_LONG).show(); Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION); intent.setData(Uri.parse("package:" + this.getPackageName())); startActivityForResult(intent, 10); } } }
这样就能正常使用外部存储了
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/tech/272346.html