A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.google.com/ar/develop/java/enable-arcore below:

Enable AR in your Android app | ARCore

Enable AR in your Android app

Stay organized with collections Save and categorize content based on your preferences.

Enable AR to use augmented reality features in your new or existing app.

Configure your app to be AR Required or AR Optional

To save space on individual devices, all AR features are stored in an app called Google Play Services for AR that is updated separately by the Play Store. Android apps that use AR features communicate with Google Play Services for AR using the ARCore SDK. An app that supports AR features can be configured in two ways: AR Required and AR Optional. This designation determines how the app interacts with the Google Play Services for AR app.

An AR Required app cannot function without ARCore. It requires an ARCore supported device that has installed Google Play Services for AR.

An AR Optional app uses ARCore to enhance existing functionality. It has optional AR features which are only activated on ARCore supported devices that have installed Google Play Services for AR.

AR Required AR Optional AR Feature usage Your app needs ARCore for basic functionality. ARCore augments your app's functionality. Your app can run without ARCore support. Play Store visibility Your app is only listed in the Play Store on devices that support ARCore. Your app follows normal listing procedures. Google Play Services for AR installation method The Play Store installs Google Play Services for AR alongside your app. Your app uses ArCoreApk.requestInstall() to download and install ARCore. Android minSdkVersion requirements Android 7.0 (API Level 24) Android 4.4 (API Level 19), though running any AR functionality requires at least Android 7.0 (API Level 24) Must use ArCoreApk.checkAvailability() or ArCoreApk.checkAvailabilityAsync() to check ARCore support and install status check_circle check_circle Must use ArCoreApk.requestInstall() to install Google Play Services for AR check_circle check_circle

To make your app AR Required or AR Optional, update your AndroidManifest.xml to include the following entries:

AR Required
<uses-permission android:name="android.permission.CAMERA" />

<!-- Limits app visibility in the 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 the app does not include any non-AR features. -->
    <meta-data android:name="com.google.ar.core" android:value="required" />
</application>
AR Optional
<uses-permission android:name="android.permission.CAMERA" />

<!-- If your app was previously 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>

Then, modify your app's build.gradle to specify a minSdkVersion of at least 24:

 android {
     defaultConfig {
         
         minSdkVersion 24
     }
 }
Add build dependencies

To add ARCore to your Android Studio project, do the following:

  1. Make sure your project's build.gradle file includes Google's Maven repository.

    allprojects {
        repositories {
            google()
            
        }
    }
    
  2. Add the latest ARCore library as a dependency in your app's build.gradle file.

    dependencies {
        
        implementation 'com.google.ar:core:1.33.0'
    }
    
Perform runtime checks

During runtime, perform the following to ensure that AR features on your app run smoothly.

Check if ARCore is supported

Both AR Required and AR Optional apps should use

ArCoreApk.checkAvailability()

or

ArCoreApk.checkAvailabilityAsync()

to determine if the current device supports ARCore. On devices that do not support ARCore, apps should disable AR-related functionality and hide associated UI elements.

Kotlin
override fun onCreate(savedInstanceState: Bundle?) {
  super.onCreate(savedInstanceState)

  // Enable AR-related functionality on ARCore supported devices only.
  maybeEnableArButton()
  
}

fun maybeEnableArButton() {
  ArCoreApk.getInstance().checkAvailabilityAsync(this) { availability ->
    if (availability.isSupported) {
      mArButton.visibility = View.VISIBLE
      mArButton.isEnabled = true
    } else { // The device is unsupported or unknown.
      mArButton.visibility = View.INVISIBLE
      mArButton.isEnabled = false
    }
  }
}
Java
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  // Enable AR-related functionality on ARCore supported devices only.
  maybeEnableArButton();
  
}

void maybeEnableArButton() {
  ArCoreApk.getInstance().checkAvailabilityAsync(this, availability -> {
    if (availability.isSupported()) {
      mArButton.setVisibility(View.VISIBLE);
      mArButton.setEnabled(true);
    } else { // The device is unsupported or unknown.
      mArButton.setVisibility(View.INVISIBLE);
      mArButton.setEnabled(false);
    }
  });
}

Even though Google Play Services for AR is installed alongside your AR Required app, users with unsupported devices might install it from an external source. Using

ArCoreApk.checkAvailability()

or

ArCoreApk.checkAvailabilityAsync()

to check for ARCore support ensures a consistent experience.

ArCoreApk.checkAvailability() may need to query network resources to determine whether the device supports ARCore. During this time, it will return UNKNOWN_CHECKING. To reduce the perceived latency and pop-in, apps should call ArCoreApk.checkAvailability() once early in its life cycle to initiate the query, ignoring the returned value. This way, a cached result will be available immediately when an AR-entering UI element might be displayed.

Check if Google Play Services for AR is installed

Both AR Required and AR Optional apps must use ArCoreApk.requestInstall() before creating an ARCore session to check whether a compatible version of Google Play Services for AR is (still) installed and to ensure that all required ARCore device profile data has been downloaded.

Kotlin
// requestInstall(Activity, true) will triggers installation of
// Google Play Services for AR if necessary.
var mUserRequestedInstall = true

override fun onResume() {
  super.onResume()

  // Check camera permission.
  

  // Ensure that Google Play Services for AR and ARCore device profile data are
  // installed and up to date.
  try {
    if (mSession == null) {
      when (ArCoreApk.getInstance().requestInstall(this, mUserRequestedInstall)) {
        ArCoreApk.InstallStatus.INSTALLED -> {
          // Success: Safe to create the AR session.
          mSession = Session(this)
        }
        ArCoreApk.InstallStatus.INSTALL_REQUESTED -> {
          // When this method returns `INSTALL_REQUESTED`:
          // 1. ARCore pauses this activity.
          // 2. ARCore prompts the user to install or update Google Play
          //    Services for AR (market://details?id=com.google.ar.core).
          // 3. ARCore downloads the latest device profile data.
          // 4. ARCore resumes this activity. The next invocation of
          //    requestInstall() will either return `INSTALLED` or throw an
          //    exception if the installation or update did not succeed.
          mUserRequestedInstall = false
          return
        }
      }
    }
  } catch (e: UnavailableUserDeclinedInstallationException) {
    // Display an appropriate message to the user and return gracefully.
    Toast.makeText(this, "TODO: handle exception " + e, Toast.LENGTH_LONG)
        .show()
    return
  } catch () {
    
    return  // mSession remains null, since session creation has failed.
  }
  
}
Java
// requestInstall(Activity, true) will trigger installation of
// Google Play Services for AR if necessary.
private boolean mUserRequestedInstall = true;

@Override
protected void onResume() {
  super.onResume();

  // Check camera permission.
  

  // Ensure that Google Play Services for AR and ARCore device profile data are
  // installed and up to date.
  try {
    if (mSession == null) {
      switch (ArCoreApk.getInstance().requestInstall(this, mUserRequestedInstall)) {
        case INSTALLED:
          // Success: Safe to create the AR session.
          mSession = new Session(this);
          break;
        case INSTALL_REQUESTED:
          // When this method returns `INSTALL_REQUESTED`:
          // 1. ARCore pauses this activity.
          // 2. ARCore prompts the user to install or update Google Play
          //    Services for AR (market://details?id=com.google.ar.core).
          // 3. ARCore downloads the latest device profile data.
          // 4. ARCore resumes this activity. The next invocation of
          //    requestInstall() will either return `INSTALLED` or throw an
          //    exception if the installation or update did not succeed.
          mUserRequestedInstall = false;
          return;
      }
    }
  } catch (UnavailableUserDeclinedInstallationException e) {
    // Display an appropriate message to the user and return gracefully.
    Toast.makeText(this, "TODO: handle exception " + e, Toast.LENGTH_LONG)
        .show();
    return;
  } catch () {
    
    return;  // mSession remains null, since session creation has failed.
  }
  
}
Request camera permission

Both AR Optional and AR Required apps must ensure that the camera permission has been granted before creating an AR Session.

Kotlin
override fun onResume() {
  super.onResume()

  // ARCore requires camera permission to operate.
  if (!CameraPermissionHelper.hasCameraPermission(this)) {
    CameraPermissionHelper.requestCameraPermission(this)
    return
  }

  
}
Java
@Override
protected void onResume() {
  super.onResume();

  // ARCore requires camera permission to operate.
  if (!CameraPermissionHelper.hasCameraPermission(this)) {
    CameraPermissionHelper.requestCameraPermission(this);
    return;
  }

  
}

Your AR activity must also implement onRequestPermissionsResult().

Kotlin
override fun onRequestPermissionsResult(
  requestCode: Int,
  permissions: Array<String>,
  results: IntArray
) {
  super.onRequestPermissionsResult(requestCode, permissions, results)
  if (!CameraPermissionHelper.hasCameraPermission(this)) {
    Toast.makeText(this, "Camera permission is needed to run this application", Toast.LENGTH_LONG)
      .show()
    if (!CameraPermissionHelper.shouldShowRequestPermissionRationale(this)) {
      // Permission denied with checking "Do not ask again".
      CameraPermissionHelper.launchPermissionSettings(this)
    }
    finish()
  }
}
Java
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] results) {
  super.onRequestPermissionsResult(requestCode, permissions, results);
  if (!CameraPermissionHelper.hasCameraPermission(this)) {
    Toast.makeText(this, "Camera permission is needed to run this application", Toast.LENGTH_LONG)
        .show();
    if (!CameraPermissionHelper.shouldShowRequestPermissionRationale(this)) {
      // Permission denied with checking "Do not ask again".
      CameraPermissionHelper.launchPermissionSettings(this);
    }
    finish();
  }
}
Comply with User Privacy Requirements

To publish your app on the Play Store, make sure that your app complies with ARCore's User Privacy Requirements.

What’s next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-02-28 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-28 UTC."],[[["Enable AR functionality in your Android app by integrating ARCore, Google's platform for building augmented reality experiences."],["Designate your app as \"AR Required\" if AR is essential or \"AR Optional\" if it enhances existing features."],["Ensure ARCore support on user devices through runtime checks and installation prompts."],["Configure your app's manifest and build dependencies to properly utilize ARCore."],["Comply with user privacy requirements before publishing your AR app on the Play Store."]]],["To implement AR in an app, configure it as AR Required or AR Optional. AR Required apps need ARCore to function, are only available on ARCore-supported devices, and the Play Store auto-installs \"Google Play Services for AR.\" AR Optional apps use ARCore to enhance features and can run on any device. Both types require runtime checks for ARCore support and installation status, utilizing `ArCoreApk.checkAvailability()` and `ArCoreApk.requestInstall()`. Camera permission must be granted, and the `AndroidManifest.xml` and `build.gradle` files must be updated.\n"]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.3