in Android development, we generally use the following code to get the storage path, and the results are generally /storage/emulated/0
in AndroidManifest. Application node in the XML file with the android: requestLegacyExternalStorage = “true” attribute, as follows: </ p>
<application
android:requestLegacyExternalStorage="true"
may be easy for developers, but for those who are new to android, it doesn’t use
now most mobile phones are Android version 10.0, when reading and writing files to the memory card, the problem of: open failed: EACCES (Permission denied) will occur. After adding the above one sentence of code to baidu, it has not been solved. The possible reason is that there is no dynamic access Permission added in the code snippet
dynamic read and write permission code:
final int REQUEST_EXTERNAL_STORAGE = 1;
if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 101);
} else {
//downloadFile();
/**
* Write the code you want to execute here
*/
}
Where is
used?
for example, we now have a button, we get its click event in the Activity, click we want to add a photo in: /storage/emulated/0/DCIM, we want to perform the operation in else
can
example:
no dynamic permissions added:
utils_get.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getDataFromokHttpUtils();
}
});
add dynamic permissions:
utils_down.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final int REQUEST_EXTERNAL_STORAGE = 1;
String[] PERMISSIONS_STORAGE = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE };
if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 101);
} else {
downloadFile();
}
}
});
</ div>
Read More:
- socket java.net.BindException: bind failed: EACCES (Permission denied)
- Ionic3 update open apk android 8.0 error FileUriExposedException
- How to Solve Error: cannot open .Git/fetch_HEAD: Permission denied
- How to Solve Vue Error: EACCES: permission denied
- (node:2233) UnhandledPromiseRejectionWarning: Error: EACCES: permission denied, mkdir ‘/usr/loca~‘
- [Solved] fatal error C1083: Could Not Open Unable to open include file:“stdint.h”: No such file or directory
- [Solved] error when starting dev server:Error: listen EACCES: permission denied 0.0.0.0:80 at Server.set
- [Solved] open failed: ENOENT (No such file or directory)
- [Solved] UE4 Android Package Error: failed for task :permission_library:compileDebugJavaWithJavac
- [Solved] Android Studio Start Error: Missing essential plugin: org.jetbrains.android Please reinstall Android
- Android Error: Android resource linking failed [How to Solve]
- [Solved] Android-android studio apk Install Error: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
- [Solved] Android app development version update failed, Android – error: task execution failed ‘: app: com
- [Solved] failed (13: Permission denied) while reading upstream
- [Solved] Android9.0 App Install Android4.4 Error: InflateException-You must supply a layout_height attribute.
- [Solved] Android Project error: import android.support.v4 (V7). App.activitycompat
- How to Solve Android Error: gps requires ACCESS_FINE_LOCATION
- JZVideo Error: Attempt to invoke virtual method ‘android.view.Window android.app.Activity.getWindow()’ on a null object reference
- [Solved] Android Error: import android.support.annotation.NonNull