Search Unity

Native VR integration (Daydream & Cardboard) blocks Android camera permission

Discussion in 'AR/VR (XR) Discussion' started by DHein, Jun 19, 2017.

  1. DHein

    DHein

    Joined:
    Jan 26, 2016
    Posts:
    38
    Hello,

    It seems like I found a bug where the usage of either cardboard or daydream for Android blocks the camera permission. Whenever I add cardboard or daydream to the player settings (VR SDK's) the app does not ask for the permission of using the camera. This results in a black camera feed without errors.
    Building the apk without both SDK's on the other hand results in the usual permission request at the start of the app. Additionally, the permission is still kept even if a new apk with Daydream and Cardboard SDK's is built.

    My assumption is that it might be caused by higher Target SDK versions for Android when using VR.
    Has anyone experienced the same issue? I couldnt find any workaround so far.

    Thanks in advance!
     
  2. greggtwep16

    greggtwep16

    Joined:
    Aug 17, 2012
    Posts:
    1,546
    While I haven't encountered this, I would assume it's caused by the android manifest that is included in the newer versions of the sdk. Have you tried editing them to ask for the permission?
     
  3. DHein

    DHein

    Joined:
    Jan 26, 2016
    Posts:
    38
    Thanks for the hint!
    Yes I have tried adding the following lines to the cardboard manifest and it did not help:

    Code (CSharp):
    1. <!-- camera permission -->
    2.   <uses-permission android:name="android.permission.CAMERA"/>
    3.   <uses-permission android:name="android.hardware.camera"/>
    4.   <uses-feature android:name="android.hardware.camera"/>
    Would I need to change the manfiest in the Unity Project or in the SDK itself?
     
  4. greggtwep16

    greggtwep16

    Joined:
    Aug 17, 2012
    Posts:
    1,546
    Either is fine, I know that the sdk has multiple manifests that get merged. You can verify that it's still present in the final manifest by building to a project and opening it up in eclipse or android studio and verifying the manifest still has the values you expect there.
     
    DHein likes this.
  5. DHein

    DHein

    Joined:
    Jan 26, 2016
    Posts:
    38
    Adding the above mentioned camera permissions to all unity project manifest files fixed the issue. Thanks!
     
    Fabien-LG and greggtwep16 like this.
  6. Fabien-LG

    Fabien-LG

    Joined:
    Mar 9, 2013
    Posts:
    15
    Hello,

    I have the same issue, but adding the permissions to the manifests didn't solve the issue.
    I have only 2 manifests in the application an AndroidManifest-Cardboard and an AndroidManifest-Daydream

    Did you had another ?
     
  7. DHein

    DHein

    Joined:
    Jan 26, 2016
    Posts:
    38
    The last time I tried it it seemed to work out for some reason, so I did not try to reproduce it.
    Nontheless this approach is not working anymore with Android 6.0.

    I found this solution involving a custom plugin: https://stackoverflow.com/questions/35027043/implementing-android-6-0-permissions-in-unity3d/

    I will try to reproduce it today and post my results here.
     
  8. DHein

    DHein

    Joined:
    Jan 26, 2016
    Posts:
    38
    Today I was able to test my plugin in order to ask for the camera permission during runtime.
    Even though I managed to follow the steps and create one, I was not able to make it work.

    First: it seems that what is blocking the permission requests at the start of the app is the activation of VR support. Without VR Support my app is asking right at launch for multiple permissions.

    When I try to ask for the permission using the plugin, the app crashes with the error message:

    Did anyone succeed by utilizing a permission plugin as well as using unity's integrated VR support?
     
  9. jknight-nc

    jknight-nc

    Joined:
    Jun 10, 2014
    Posts:
    52
  10. DHein

    DHein

    Joined:
    Jan 26, 2016
    Posts:
    38

    Thanks for your reply! I will take a look at the plugin.
     
  11. DHein

    DHein

    Joined:
    Jan 26, 2016
    Posts:
    38
    So after some bug fixing I was able to finally make the permission plugin work!

    For anyone who does not want to know the details but still needs the permissions, you can simply download the .jar file from here.
    Special thanks to jknight-nc's excellent tutorial, I hope you approve that I post the .jar file here although I used some of your code from the stack overflow post.

    You need the setup as described in jknight-nc's tutorial mentioned above, in order to use it properly.
    This is an example how the plugin can be used and what permission types are implemented:

    Code (CSharp):
    1. public class PermissionHandler
    2. {
    3.     /// <summary>
    4.     /// Grants runtime Android permission
    5.     /// </summary>
    6.     /// <param name="permissionName">Grants one of the following permissions:
    7.     /// CAMERA, READ_EXTERNAL_STORAGE, ACCESS_COARSE_LOCATION, ACCESS_NETWORK_STATE, NFC, INTERNET, INTERNET, READ_CONTACTS</param>
    8.     public static void GrantPermission(string permissionName)
    9.     {
    10. #if UNITY_ANDROID
    11.         AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    12.         AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
    13.  
    14.         var jc = new AndroidJavaClass("com.iqi.vr.androidpermission.PermissionGranter");
    15.         jc.CallStatic("grantPermission", currentActivity, permissionName);
    16. #endif
    17.     }
    18. }
    In order to make your own plugin you can read the following tutorial:
    http://www.thegamecontriver.com/2015/04/android-plugin-unity-android-studio.html
    Following the above mentioned guides properly fixes the bugs I have encountered.
    If anyone has any problems concerning this, I am happy to help and provide the Android Studio project.
     
    Last edited: Oct 4, 2017