[TIMOB-26238] Android: Storage-permissions issue on Android 8 (API 26+)
GitHub Issue | n/a |
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2018-07-26T16:31:04.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Android |
Labels | Android8.0, Permissions |
Reporter | Jorge Macias Garcia |
Assignee | Shak Hossain |
Created | 2018-07-26T08:52:39.000+0000 |
Updated | 2018-07-26T16:34:11.000+0000 |
Description
I've made a four different ways to check and request storage permissions. One of them fails, combining *Ti.Android.hasPermission* and *Ti.filesystem.requestStoragePermissions*
I attached the sample app. Special attention in tiapp.xml. The permission WRITE_EXTERNAL_STORAGE is declared explicitly in the android manifest section and the override property set to true.
After each test, if you disable storage permissions manually from app settings page the log will be disconnected. For a correct testing:
Uninstall the app and build again.
Behaviour:
*First execution trace*
Check permissions with: Ti.Android.hasPermission
Requesting permissions with: Ti.Filesystem.requestStoragePermissions
hasStoragePermission
Ti.Android.hasPermission("android.permission.WRITE_EXTERNAL_STORAGE"): false
requestFilesystemPermission
Ti.Filesystem.requestStoragePermissions
[Prompt permission grant dialog] Allow
requestPermissionCallback
Permission Filesystem permission granted.
Finished
OK -> Permission granted
Trying again
Check permissions with: Ti.Android.hasPermission
Requesting permissions with: Ti.Filesystem.requestStoragePermissions
hasStoragePermission
Ti.Android.hasPermission("android.permission.WRITE_EXTERNAL_STORAGE"): false
requestFilesystemPermission
Ti.Filesystem.requestStoragePermissions
FAIL
*Second execution trace*
Check permissions with: Ti.Android.hasPermission
Requesting permissions with: Ti.Filesystem.requestStoragePermissions
hasStoragePermission
Ti.Android.hasPermission("android.permission.WRITE_EXTERNAL_STORAGE"): false
requestFilesystemPermission
Ti.Filesystem.requestStoragePermissions
FAIL
Other 3 combinations works fine:
*Native method:*
Check permissions with: Ti.Android.hasPermission
Requesting permissions with: Ti.Android.requestPermissions
OK
*Filesystem method:*
Check permissions with: Ti.Filesystem.hasStoragePermissions
Requesting permissions with: Ti.Filesystem.requestStoragePermissions
OK
*Mixed method B:*
Check permissions with: Ti.Filesystem.hasStoragePermissions
Requesting permissions with: Ti.Android.requestPermissions
OK
Attachments
This is not a bug. The
Ti.Filesystem.requestStoragePermission()
requests theREAD_EXTERNAL_STORAGE
permission. It does *+not+* request theWRITE_EXTERNAL_STORAGE
. https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Filesystem-method-requestStoragePermissions Android used to be lenient about this where if the end-user grantedREAD_EXTERNAL_STORAGE
permission, your app would also be grantedWRITE_EXTERNAL_STORAGE
permission since they were both in the same permission group. But Google has changed this for apps which target Android 8.0 or higher, which Titanium 7.3.0 does by default now. Google documents this here... https://developer.android.com/about/versions/oreo/android-8.0-changes#rmp Please see the attached [^CameraExternalTest.js]. You would not normally request permissions separately like this, but it proves that permission request/detection works. The point being, is if you wantWRITE_EXTERNAL_STORAGE
, you need to specifically request it. I hope this helps.It's clear! Thanks.