Android设备文件访问权限不显示问题及权限配置求助
First, let’s tackle the critical code error in your implementation, then break down why the permission option is missing based on Android version changes.
1. Fix Duplicate onRequestPermissionsResult Methods
Looking at your code, you’ve defined two separate onRequestPermissionsResult methods. This is a bug—only the second one will execute, meaning your camera permission result handling is completely ignored. Merge them into a single method:
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == CAMERA_PERMISSION_CODE) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { Toast.makeText(MainActivity.this, "Camera Permission Granted", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(MainActivity.this, "Camera Permission Denied", Toast.LENGTH_SHORT).show(); } } else if (requestCode == STORAGE_PERMISSION_CODE) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { Toast.makeText(MainActivity.this, "Storage Permission Granted", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(MainActivity.this, "Storage Permission Denied", Toast.LENGTH_SHORT).show(); } } }
2. Understand Android 13+ Permission Changes
The missing "File access" option is almost certainly because your device runs Android 13 (API 33) or higher. Google replaced broad storage permissions with granular media permissions and removed the separate "File access" entry in settings. Here’s how to adjust:
Update Manifest Permissions
If your app targets API 33+, replace the old storage permissions with these granular media permissions:
<uses-permission android:name="android.permission.CAMERA" /> <!-- For accessing images, videos, audio --> <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" /> <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" /> <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" /> <!-- Optional: Only needed for writing media files on devices below API 33 --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="32" /> <!-- Only use this if you need full access to all files (requires Google Play approval) --> <!-- <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" /> -->
Adjust Permission Request Logic
Update your storage permission request to use the new media permissions instead of WRITE_EXTERNAL_STORAGE. For example, if you need access to images:
// Update the permission code and request logic private static final int MEDIA_PERMISSION_CODE = 101; // In your storage button onClick listener: checkPermission(Manifest.permission.READ_MEDIA_IMAGES, MEDIA_PERMISSION_CODE);
3. For Android 12 or Lower Devices
If your device runs Android 12 (API 32) or older, the "File access" option should appear if you’ve set up permissions correctly. Double-check:
- Your
targetSdkVersionis set to 32 or lower in yourbuild.gradlefile. - You’ve fixed the duplicate
onRequestPermissionsResultmethod mentioned earlier.
Key Takeaways
- On Android 13+, the "Photos and media" permission in settings replaces the old "File access" option for media files (images, videos, audio).
- If you need access to non-media files (like documents or downloads), you’ll need the
MANAGE_EXTERNAL_STORAGEpermission—but this is restricted to specific use cases (e.g., file managers) and requires Google Play approval.
内容的提问来源于stack exchange,提问作者achal naskar




