Introduction
ARCore is google’s one of the best platforms to build and deploy AR-experienced applications. ARCore provides different APIs that enable your phone to understand your phone environment and react according to the information that got from the environment. ARCore mainly provides three capabilities as Motion Tracking - which makes the phone understand and track its position relative to the earth, Environmental Understanding - which makes your phone understand the environment and interact with it, Light Estimation - estimates the current lighting conditions. We will learn more about the ARCore, and how to enable and use it on our devices.
Steps Involved
In Order to enable ARCore on our app, we need to follow the below steps:
Step 1 - > For your app, choose between AR Required and AR Optional.
Step 2 - > Add the above-selected entries to your app manifest.
Step 3 - > Add Build Dependencies to your project or app.
Step 4 - > Perform runtime checks such as whether the device supports ARCore or not, Camera Permissions are granted or not, etc.
Step 5 - > To make sure your app complies with ARCore’s User Policy Requirements.
AR Required or AR Optional
AR Required: An AR Required App must run only with ARCore enabled. It won't work without ARCore.To use this AR Required app, the device must be ARCore Supported device, and it has Google Play Services for AR installed.
AR Optional: On the other hand, the AR Optional Apps function differently. They provide different functionalities. Here these devices have optional AR features that enable only when the device supports AR, and the app has Google Play Servies for AR installed in it.
You can learn more differences about these through this link.
Add entries to your manifest.xml file.
Modify the manifest.xml file with the below code:
For AR Required:
<uses-permission android:name="android.permission.CAMERA" />
<!-- Limits app visibility in Google Play Store to ARCore supported devices
(https://developers.google.com/ar/devices). -->
<uses-feature android:name="android.hardware.camera.ar" />
<application …>
…
<!-- "AR Required" app, requires "Google Play Services for AR" (ARCore)
to be installed, as app does not include any non-AR features. -->
<meta-data android:name="com.google.ar.core" android:value="required" />
</application>
For AR Optional:
<uses-permission android:name="android.permission.CAMERA" />
<!-- If your app was AR Required, don't forget to remove the
`<uses-feature android:name="android.hardware.camera.ar" />` entry, as
this would limit app visibility in the Google Play Store to only
ARCore supported devices. -->
<application …>
…
<!-- "AR Optional" app, contains non-AR features that can be used when
"Google Play Services for AR" (ARCore) is not available. -->
<meta-data android:name="com.google.ar.core" android:value="optional" />
</application>
And maintain at least minimum SDK versions. For AR Required, it should be a minimum 14th version, and for AR Optional, it should be at least the 24th version..
Addition of build dependencies
To add ARCore to your project, make sure your build-gradle file contains Google Maven Repo as
allprojects {
repositories {
google()
…
}
}
And add the latest ARCore library as
dependencies {
…
implementation 'com.google.ar:core:1.30.0' }
Performing Runtime Checks
To check whether ARCore is supported or not, both AR Required and AR Optional use a method called ArCoreApk.checkAvailability() to check if the ARCore is supported or not. Some AR not supported devices may install Google Play services for AR from the external resources, this will also be checked by this method whether the resource is an unknown resource or not. It will return UNKNOWN_CHECKING in that case.
To request Camera Permissions, we need to take help from the CameraPermissionHelper class that is built to access permissions for the camera.
User Privacy Requirements Compliance
Make sure every app that is designed to use ARCore satisfies User Privacy Requirements.