Augmented Reality with ARCore SDK Android

Farman
3 min readJan 26, 2021

--

The blend of virtual and real world has brought our imagination to reality. As Virtual reality generates realistic images, sounds, and other sensations that put spectacular imaginary world around you, on the other hand, Augmented Reality adds virtual stuff to your real world environment.

Virtual Reality: VR is fully immersive, which drags your senses into a virtual world apart from the real one. It is a computer-generated world of imagery and sounds in which you can manipulate objects and move around using haptic controllers while tethered to a console or PC.

Photo by Jessica Lewis on Unsplash

Augmented Reality: AR overlays digital information on real-world elements. Augmented reality keeps the real world central but enhances it with other digital details.

Photo by UNIBOA on Unsplash

NOTE: We have also Mixed Reality (MR) and Extended Reality (XR). MR combines both VR and AR, whereas XR includes VR, AR and MR technologies that enhance our senses and may give totally unreal, simulated worlds for us to experience.

Augmented Reality in Android Application:

Google provides ARCore SDK for building augmented reality experiences. ARCore is leveraged with many apis which enables mobile to receive and interact with the information of surrounding world. AR experience is achieved using mainly three key capabilities of ARCore, to blend virtual content with the real world.

  • Motion tracking allows the phone to understand and track its position relative to the world.
  • Environmental understanding allows the phone to detect the size and location of all type of surfaces.
  • Light estimation allows the phone to estimate the environment’s current lighting conditions.

ARCore’s understanding of the real world lets you place objects, annotations, or other information in a way that integrates seamlessly with the real world.

This will be very basic Augmented Reality experience using ARCore SDK in android App, so let’s create new android project with Empty Activity and Kotlin as language (choose as Java if you prefer) in Android Studio.

  • Modify build.gradle to include following entries of ARcore and sceneform SDK.
plugins {
...
id 'com.google.ar.sceneform.plugin'
}

android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
...
implementation 'com.google.ar:core:1.22.0'
implementation 'com.google.ar.sceneform.ux:sceneform-ux:1.17.1'
implementation 'com.google.ar.sceneform:core:1.17.1'
implementation "com.google.ar.sceneform:animation:1.17.1"
}
  • Add classpath for sceneform in project level build.gradle file
dependencies {
...
classpath 'com.google.ar.sceneform:plugin:1.17.1'
}
  • Modify your AndroidManifest.xml to include the following entries for Camera, OpenGL ES and google play service for AR.
<uses-permission android:name="android.permission.CAMERA" /><uses-feature android:name="android.hardware.camera.ar" /><uses-feature android:glEsVersion="0x00030000"  
android:required="true"/>
<application ... >
...
<meta-data android:name="com.google.ar.core"
android:value="required"/>
</application>
  • Adding AR fragment in layout activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<fragment
android:name="com.google.ar.sceneform.ux.ArFragment"
android:id="@+id/fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>

And no changes for MainActivity now and we are good to go.

class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}

After running the application on the device, It will launch the camera with a hand overlay (if all setup is good🙂).

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Farman
Farman

Written by Farman

Learner, enthuisast and Android Dev. The best way to learn and stay up to date is simply to do something.

No responses yet

Write a response