Search Unity

help with OBB READ/WRITE_EXTENAL_STORAGE

Discussion in 'Android' started by BrianND, Jul 10, 2020.

  1. BrianND

    BrianND

    Joined:
    May 14, 2015
    Posts:
    82
    So I'm not sure if this is a bug or not.

    I heard Unity adds android:maxSdkVersion="18" to
    Code (CSharp):
    1. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" >
    because of this

    https://developer.android.com/reference/android/Manifest.permission#WRITE_EXTERNAL_STORAGE

    But when I call
    Code (CSharp):
    1. if (Permission.HasUserAuthorizedPermission(Permission.ExternalStorageWrite))
    2. {
    3. }
    on API level 19 or greater Unity returns false. Is this right? because permission is implicitly granted if API level is 19 or greater. This also seems to mute RequestPermission popup.

    So the only solution I could think of was something like this
    Code (CSharp):
    1. if(API < 19)
    2. {
    3.    check write permission
    4.    if(can write external)
    5.    {
    6.      download OBB
    7.    }
    8.    else
    9.    {
    10.       request external write
    11.       try to download again
    12.    }
    13. }
    14. else
    15. {
    16.   download since permission implicitly granted
    17. }
    I'm doing this to handle edge cases when the user fails to download an OBB or their permissions are not correct which does happen in production.

    Am I doing something wrong or is it a bug that HasUserAuthorizedPermission(UnityEngine.Android.Permission.ExternalStorageWrite) return false on API 19 or greater.