Augmented Reality In Android

Posted By : Aman Srivastava | 07-Jan-2021

Arcore is the android SDK to use augmented reality within android mobile applications.ARCore SDKs make AR features available on ARCore supported devices that have Google Play Services for AR (ARCore) installed. 


To enable ArCore you need to perform the following steps : 

  1. Add Ar entries to the manifest file.
  2. Add dependencies to build.gradle.
  3. Implementation.


Add To Manifest - 

You need to add the following permission and metadata to your AndroidManifest.xml file for ARCore configuration in your application:

<uses-permission android:name="android.permission.CAMERA" />
        android:required="true" />


And inside application tag - 

            android:value="required" />


Also Read: Unlocking the potential of Immersive VR using Unity


Add Dependencies


In the project's build.Gradle : 

classpath ''

In app's build.Gradle : 

implementation ''

In app's Gradle file : 

apply plugin: ''




  • Add models(OBJ and GLTX extension) into project : 

3D models to render must have either .obj or .gltx extension, you can download the sample models from

Create sampledata directory in your project and add .obj and .mtl downloaded files.

Then right-click on the obj file and choose import as sceneform assets.

As a result, the Renderable AR sceneform assets gets automatically created. Also the following lines at the end of the app’s build.gradle will be automatically added:

sceneform.asset('sampledata/Coffee Cup_final.obj',
        'sampledata/Coffee Cup_final.sfa',
        'src/main/assets/Coffee Cup_final')


  • Add ArFragment into your XML file : 

<fragment android:id="@+id/sceneForm" android:name="" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" />

  • Initialize ArFragment into file : 

arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(;

  • Create a method addObject() to get hit points on the plane using motion tracking :
private void addObject(Uri model) {
    Frame frame = fragment.getArSceneView().getArFrame(); pt = getScreenCenter();
    List<HitResult> hits;
    if (frame != null) {
        hits = frame.hitTest(pt.x, pt.y);
        for (HitResult hit : hits) {
            Trackable trackable = hit.getTrackable();
            if (trackable instanceof Plane &&
                    ((Plane) trackable).isPoseInPolygon(hit.getHitPose())) {
                modelLoader.loadModel(hit.createAnchor(), model);


The call of addObject() will be from the onCreate method with Uri of the model as a param :



  • Now once the plane is detected we need to load the model, so let's create the class ModelLoader with a method loadModel() inside it : 
public class ModelLoader {
    private final WeakReference<MainActivity> owner;
    private static final String TAG = "ModelLoader";

    ModelLoader(WeakReference<MainActivity> owner) {
        this.owner = owner;

    void loadModel(Anchor anchor, Uri uri) {
        if (owner.get() == null) {
            Log.d(TAG, "Activity is null.  Cannot load model.");
                .setSource(owner.get(), uri)
                .handle((renderable, throwable) -> {
                    MainActivity activity = owner.get();
                    if (activity == null) {
                        return null;
                    } else if (throwable != null) {
                    } else {
                        activity.addNodeToScene(anchor, renderable);
                    return null;

  • Now as soon as the model is loaded we need to place the model to the scene, so let's make a method for that : 
public void addNodeToScene(Anchor anchor, ModelRenderable renderable) {
    AnchorNode anchorNode = new AnchorNode(anchor);
    TransformableNode node = new TransformableNode(fragment.getTransformationSystem());




You will find your 3D model loaded on your screen as soon as the scene is detected.


Note: Make sure to use the latest version of sceneform package in your project.


Also Read: Understanding The Lifecycle of Custom View In Android


Choose Oodles For AR App Development


We are a seasoned AR VR app development company that specializes in building high-quality virtual reality apps that deliver immersive user experiences. Our development team uses advanced frameworks and tools like Unity, Vuforia, Argon.js, and React VR to build high-graphics VR apps that maximize user engagement. Explore our augmented reality app development services here. For more information, contact us at

Related Tags

About Author

Author Image
Aman Srivastava

Aman is a passionate Mobile Application Developer, who likes to explore and implement new technologies.

Request for Proposal

Name is required

Comment is required

Sending message..