Search Unity

How to detect if an android device really needs read permission to access the obb

Discussion in 'Android' started by Santiago-Mas-Gutierrez, Apr 22, 2019.

  1. Santiago-Mas-Gutierrez

    Santiago-Mas-Gutierrez

    Joined:
    May 31, 2017
    Posts:
    8
    Hello!

    We are currently developing a video game, and at the moment, the Android version is around 250MB, so we need to use an OBB expansion file to be able to publish it in the Play Store.

    We have already integrated the script that requests read permission at run time to mount the OBB. We would like to request this permission ONLY if the device really needs it. We have done some tests with devices with Android 7 and 8 in which we have been able to access the OBB correctly without requesting permission.

    The Android Developers documentation (https://developer.android.com/google/play/expansion-files) says the following: "For Android (version 6 and later), external storage permission needs to be requested at runtime, but some implementations of Android do not require permission to read OBB files."

    There is also an example in Java of how to detect the need for permission, but we would not know how to perform this check in Unity. Does anyone know any method?

    Thanks in advance.
     
  2. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    836
    Since Unity 2018.3 runtime permissions can be requested at any time during the runtime, not only at the start up. With that feature, we've made sure that when loading OBB file we will request the read external storage permission only if it is needed.

    If you are using an older Unity version, then this is problematic. What you could try to do is in the first scene get the Application.dataPath value (https://docs.unity3d.com/ScriptReference/Application-dataPath.html) and try to determine if the path points to the apk or obb location. If it will point to the apk location, then you will know that obb loading has failed.
     
  3. pintianz

    pintianz

    Joined:
    Mar 1, 2015
    Posts:
    25
    I facing similar problem right now (apk + obb) where a load asset bundle from file locally does not work. I'm using 2018.3.14 so this shouldn't be an issue with unity version. Do you know how I may fix this?
     
  4. Santiago-Mas-Gutierrez

    Santiago-Mas-Gutierrez

    Joined:
    May 31, 2017
    Posts:
    8
    Thanks JuliusM!

    We are currently using 2018.2.21f Unity version. Due to some Assets that we use, we can not update version in this moment.

    By checking the value returned by Application.dataPath we have been able to determine if the app has access to the obb file.

    Just one more doubt, would there be any way to differentiate if app do not has access to the obb file for not having permissions or because the obb file does not exist?

    I will try to explain it better below:

    The method that we currently use is:
    1. Check if the value returned by Application.dataPath contains the substring "obb". If yes, load the next scene.
    2. If the value returned by Application.dataPath does not contain the substring "obb", it asks the user for read permission. Then check again the value returned by Application.dataPath and:
      1. If the return value contains the substring "obb" it loads the next scene.
      2. If the returned value does not contain the substring "obb" it is because the obb file does not exist. How could this point be found (the obb file does not exist) without the need to ask for read permission for those devices that do not need it?
    Excuse my English, I hope to have explained myself well. Greetings.
     
  5. mgrigsby

    mgrigsby

    Joined:
    May 16, 2016
    Posts:
    3
    We have found that on some devices we need to force a restart of the application after requesting read permission before it will actually allow reading.
     
  6. MetaDOS

    MetaDOS

    Joined:
    Nov 10, 2013
    Posts:
    157
    Hi. Is it possible to use OBB without requiring writing external storage?
     
  7. Santiago-Mas-Gutierrez

    Santiago-Mas-Gutierrez

    Joined:
    May 31, 2017
    Posts:
    8
    Some android devices don't need external storage permission to access to OBB file.

    We could detect it checking the value returned by Application.dataPath. If the value contained the substring "obb", don´t require permission, otherwise we ask for permission.

    Edit: sorry, my reply was for read external storage permission, not for write external storage. I think write external storage is not necessary for access to the obb.