Are you struggling with the 'open failed: EPERM (Operation not permitted)' error on your computer or device? This frustrating error can occur for a variety of reasons, from permission issues to software conflicts. In this post, we'll walk you through the steps to diagnose and fix this error, so you can get back to using your device without any trouble.
In This post, we will learn how to ask the user for storage permission for saving any file like mp3, mp4, pdf, text, or any type of file format. So follow the below steps to do that.
Step 1: Add the following code to AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
Step 2: Add the following code in.MainActivity.kt
if (Environment.isExternalStorageManager()) {
// The app has been granted the MANAGE_EXTERNAL_STORAGE permission
} else {
// The app has not been granted the MANAGE_EXTERNAL_STORAGE permission
// Request the permission from the user
val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
intent.data = Uri.parse("package:" + packageName)
startActivity(intent)
}
that's it. now run your app and check error will be gone. watch the below video if you don't understand the above steps.