Search Unity

Anyway to stop Vuforia asking for camera permission at startup? (Android)

Discussion in 'Vuforia' started by CDF, Jun 8, 2018.

  1. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    First off, this is only an issue when splitting the APK into a .obb file. Single APK works fine.

    I'm using this library here which works great: https://github.com/Over17/UnityAndroidPermissions

    Vuforia version is: 7.0.50
    Unity version is: 2017.4.4f1

    Can't upgrade to 2018.1.

    I've tried everything, from steps described in these places:
    https://forum.unity.com/threads/use...n-individual-scene-not-entire-project.498489/
    https://forum.unity.com/threads/use...scene-not-entire-project.498489/#post-3363651
    https://forum.unity.com/threads/do-not-run-vufory-when-the-application-starts.498351/

    Here is my configuration:

    vuforia.jpg

    Immediately when the first scene (A scene that only needs to download an OBB) is loaded:

    permission.jpg

    This does not happen when building a single APK file.

    Is there something I can do? Is this a known issue? Do I have no other choice but to upgrade to 2018.1?
     
  2. thibouf

    thibouf

    Joined:
    Mar 17, 2017
    Posts:
    105
    Hey, I got the same probleme here ... I can initialize Vuforia at runtime when I want, but the camera permission request keeps popping on the splash screen ...

    Did you (or someone else ) found a solution ?

    (Using 2018.2)
     
  3. meedabit

    meedabit

    Official Vuforia Employee Vuforia

    Joined:
    Dec 8, 2016
    Posts:
    266
  4. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    The problem is we don't want the camera initialized at startup.
    As stated in the initial post, the issue only occurs when needing to load an OBB expansion file.
    If the APK is a single binary, the issue does not occur.
     
  5. thibouf

    thibouf

    Joined:
    Mar 17, 2017
    Posts:
    105
    Yes, the problem is not asking for permissions (that is normal), the problem is asking for permission right at startup, even if the AR feature is not immediately started... Permission request on android should only appear right when we start using the camera / initialize Vuforia...

    Also personally, I do get the permission request on start even with on single binary APK ... @CDF how did you manage to not get it ?
     
  6. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    I never did solve the OBB thing, but for a single APK, I think you just need to add:

    <meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="true" /> in your Manifest, and add a disabled "VuforiaBehaviour" to your camera in the first scene.

    I used this library for permissions: https://github.com/Over17/UnityAndroidPermissions

    However, from the 2018.3 Beta release notes, it says: "Android: Added support for requesting permissions at runtime for apps using API level 23 and above." So Unity may have added this internally now?

    Ah, this is it: https://docs.unity3d.com/2018.3/Documentation/Manual/android-RequestingPermissions.html
     
  7. thibouf

    thibouf

    Joined:
    Mar 17, 2017
    Posts:
    105
    Thank you @CDF ! That's exactly what I was looking for :)
    I hope someone will help you find the solution when using OBB

    @meedabit I now understand that it is a Unity problem, but as Vuforia is already adding automatically the permissions list in the manifest, it would feel logical to get an option in Vuforia to do all this automatically (setting the SkipPermissionsDialog to true in the manifest + allowing to request permission when initializing Vuforia). Or at least an explanation somewhere in the documentation
     
  8. meedabit

    meedabit

    Official Vuforia Employee Vuforia

    Joined:
    Dec 8, 2016
    Posts:
    266
    Hello,

    Vuforia will not try and open the camera unless init is called.

    Perhaps the Delayed Initialization is an option (see bottom of article)? In order to use it, you'll need to call the following line of code before an ARCamera is started: VuforiaRuntime.Instance.InitVuforia();

    We've been able to confirm this works in our sample project using the following steps:
    1. Check the Delayed Initialization box (Window->Vuforia Configuration).
    2. Create a new scene.
    3. Add a script to any object in the scene.
    4. Add these two lines of code to the Start() function of this new script:
      1. VuforiaRuntime.Instance.InitVuforia();
      2. UnityEngine.SceneManagement.SceneManager.LoadScene( "Vuforia-3-ImageTargets" );
    5. Open Build Settings and add the scene made in the steps above as well as the Vuforia-3-ImageTargets scene to the list of scenes in build.
    6. Build to device (or in playmode)
    Thanks,
    Vuforia Engine Support
     
    chenkopel likes this.
  9. thibouf

    thibouf

    Joined:
    Mar 17, 2017
    Posts:
    105
    Yes, delayed initialization is THE option. But that is not what we are talking about. Let me reexplain :

    When enabled Vuforia automatically add CAMERA permission in the android manifest. So, by default, on Android, even if Vuforia is not initialized unity will request the camera permission at startup.

    My goal was to delay the permission request until the user start the AR mode . As pointed out by CDF , this is actually possible by adding the SkipPermissionsDialog in the android manifest, but then you need a plugin to trigger the permission request on demand. This is the part that was quite hard to find for me. And that's why I pointed out that it could be explain somewhere in the documentation , and even better , it could done automatically thanks to an option in Vuforia settings.
     
  10. meedabit

    meedabit

    Official Vuforia Employee Vuforia

    Joined:
    Dec 8, 2016
    Posts:
    266
    Hello @thibouf,

    Thanks for the clarification. Makes sense to me now. I'll open a ticket to evaluate this as a feature.

    Thanks,
    Vuforia Engine Support
     
    AM-Dev likes this.
  11. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    Nice, also please take into account the original issue:

    even with SkipPermissionsDialog, Camera permission popup still shows when splitting binary (OBB File)
     
  12. meedabit

    meedabit

    Official Vuforia Employee Vuforia

    Joined:
    Dec 8, 2016
    Posts:
    266
    Hello,

    Note that this functionality can behave very differently depending on the Unity version and Android Target SDK version:
    • With the Android Target SDK version that all our native Android samples use (Android 23?), the manifest still defines which permissions will be requested at startup.
    • With newer Android Target SDK versions, the apps need to request permissions at runtime, and we do this automatically in Vuforia::init(). However, until Unity 2018.2, Unity used to scan the manifest and ask for all permissions at app start, so the only way to delay the camera permission dialog is to remove the permission from the manifest.
    • With Unity 2018.3, Unity no longer asks for all permissions in the manifest autmatically, so the camera permission dialog will only be shown once Vuforia is initialized.
    Thanks,
    Vuforia Engine Support