'Need to create a folder for my Android application in Internal Storage
I am creating an android application where I need to create a folder in Internal Storage to store the files generated by user (Just like how whatsapp creats one in Internal storage). I was using MANAGE_EXTERNAL_STORAGE permission but google has rejected my app because of it, and no other way is working for that. If there is any other permission or way of doing this it will be very helpful.
The File.mkdirs() is not creating folder.
I have tried other ways as mentioned here, but none of them work. Android- Saving Internal Storage to my created folder
How to create application specific folder in android gallery?
File.mkdirs() is giving false for that.
My code:
AndroidManifest:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
Requesting for permissions:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val intent =Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
val uri = Uri.fromParts("package", packageName, null)
intent.data = uri
startActivity(intent)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val intent =Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES)
val uri = Uri.fromParts("package", packageName, null)
intent.data = uri
startActivity(intent)
}
val permissions: Array<String> = arrayOf(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission_group.STORAGE,
Manifest.permission.MANAGE_DOCUMENTS,
Manifest.permission.INSTALL_PACKAGES
)
//requestPermissions(permissions, PackageManager.PERMISSION_GRANTED)
requestPermissions(permissions, 1)
Creating folder in internal storage:
val folder = "/storage/emulated/0/"+
getString(R.string.foldername)
val path = folder + File.separator.toString() + getString(R.string.lbl_Order)+orderModelClass!!.name+ ".pdf"
if (!File(folder).exists()) {
File(folder).mkdirs()
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|