Search Unity

[ARFoundation] Support Device check on android does not work correctly

Discussion in 'AR/VR (XR) Discussion' started by TFan, Jul 5, 2019.

  1. TFan

    TFan

    Joined:
    Oct 1, 2016
    Posts:
    1
    I wanna make AR and non AR version for android with AR Foundation
    (Unity 18.3 ,ARF-1.5 prev.5, ARCore -2.1 p.5, ARKit - 2.1 p.5 as well )
    So i want to check platform is supporting AR or not for implimintation diffrent logics .
    I tried to use sample for device support check https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@2.1/manual/index.html
    on Non AR scene.
    But anyway on devices that have android version 7 whitch are not support ARCore every launch it
    redirect to play market to instal ARCore despite it is dont support it. Only then i close redirect tab it say that device dont support but this redirect happens every launch.

    Devices : xiaomi redmi 6a and Huawei Y9 2018.
    Also i tried to turn off attemp update option and in project settings make ARcore+Arkit is optional.
    Anyone know a solution?
     
  2. unity_0HhWrJloljIATg

    unity_0HhWrJloljIATg

    Joined:
    May 15, 2019
    Posts:
    3
    Also getting this problem on Samsung Galaxy S6, Android version 7.0, Unity 2018.4.3f1, AR Foundation 1.5.0-preview.5, AR Core plugin, 2.1.0-preview.5.
     
  3. Andy_liu

    Andy_liu

    Joined:
    Oct 27, 2014
    Posts:
    26
    Same problem with me, are there any solution?
     
  4. evgro

    evgro

    Joined:
    Oct 5, 2016
    Posts:
    7
    As Google Play Services for AR is automatically installed and updated on supported devices you can check if ARCore is supported this way.

    Code (CSharp):
    1.         public static bool IsARCoreSupported()
    2. {
    3.             var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    4.             var context = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
    5.             var packageManager = context.Call<AndroidJavaObject>("getPackageManager");
    6.             AndroidJavaObject packageInfo = null;
    7.             try
    8.             {
    9.                 packageInfo = packageManager.Call<AndroidJavaObject>("getPackageInfo", "com.google.ar.core", 0);
    10.             }
    11.             catch
    12.             {
    13.  
    14.             }
    15.             if (packageInfo != null)
    16.                 return true;
    17.             else
    18.                 return false;
    19.         }
    20.  
    Also you can use ARSupportChecker plugin that does exactly that stuff:
    Code (CSharp):
    1. ARSupportChecker.IsSupported()
     
  5. KirillKuzyk

    KirillKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    420
    In my experience, there is no guarantee that 'Google Play Services for AR' is installed on supported devices automatically. Also, a user can remove this service manually. In these cases, your script will produce a false negative result.

    I prefer to use this AR Foundation API to determine the support. It will work correctly only if ARCore is set to 'Optional' in XR Plug-in Management.

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3. using UnityEngine.XR.ARFoundation;
    4.  
    5.  
    6. public class CheckAvailability : MonoBehaviour {
    7.     IEnumerator Start() {
    8.         yield return ARSession.CheckAvailability();
    9.         Debug.Log($"ARSession.CheckAvailability() finished with state: {ARSession.state}");
    10.    
    11.         // ARSession.CheckAvailability() can finish with state ARSessionState.Installing if an update for AR Services is required. So we wait.
    12.         while (ARSession.state == ARSessionState.Installing) {
    13.             yield return null;
    14.         }
    15.    
    16.         if (ARSession.state == ARSessionState.NeedsInstall) {
    17.             Debug.Log("Installing AR provider...");
    18.             yield return ARSession.Install();
    19.         }
    20.    
    21.         Debug.Log($"AR is supported in this device: {ARSession.state >= ARSessionState.Ready}");
    22.     }
    23. }
    24.  
     
  6. evgro

    evgro

    Joined:
    Oct 5, 2016
    Posts:
    7
    The method with ARSession.CheckAvailability() returns false positive result on some devices and redirects devices that are not supported AR to the Google Play, what is frustrated for users. You can see such behaviour on Redmi Note 5 and some other Xiaomi devices. On the other hand on the most devices this package is undeletable and preinstalled.
     
  7. KirillKuzyk

    KirillKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    420
    I can only reproduce this redirection if ARCore is set to Required. Are you sure you've tested my method with ARCore set to Optional on Redmi Note 5?
     
  8. evgro

    evgro

    Joined:
    Oct 5, 2016
    Posts:
    7
    Yep, AR Core is Optional, it's reproducible on Redmi Note 4 and Redmi Note 5.
     
    KirillKuzyk likes this.
unityunity