I have an activity in no 'app' module where I should use WRITE_EXTERNAL_STORAGE permission. Method onRequestPermissionsResult not called in this module. My code to start this runtime permission
private fun requestPermissions() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
viewModel?.initTree()
} else {
val storagePermission = Manifest.permission.WRITE_EXTERNAL_STORAGE
val hasPermission = checkSelfPermission(storagePermission)
val permissions = arrayOf(storagePermission)
if (hasPermission != PackageManager.PERMISSION_GRANTED) {
requestPermissions(permissions, PERMISSION_WRITE_EXTERNAL_STORAGE_REQUEST_CODE)
} else {
viewModel?.initTree()
}
}
}
And onRequestPermissionsResult
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<String>,
grantResults: IntArray
) {
if (requestCode == PERMISSION_WRITE_EXTERNAL_STORAGE_REQUEST_CODE) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
viewModel?.initTree()
} else {
Toast.makeText(this, R.string.permission_required, Toast.LENGTH_SHORT).show()
}
}
}
I have tried to use method ActivityCompat.requestPermissions() and add call super.onRequestPermissionsResult() but it haven't help me. Then I tried to add my code to activity in app module and it works properly.
What the reason of my trouble?
UPD: AndroidManifest.xml in no 'app' module
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ru.anthony_kharin.file_manager">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application android:requestLegacyExternalStorage="true">
<activity
android:name=".view.FileExplorerActivity"
android:theme="@style/Theme.FileManagerLibrary" />
</application>