अपने Android ऐप्लिकेशन में एआर की सुविधा चालू करना

अपने नए या मौजूदा ऐप्लिकेशन में ऑगमेंटेड रिएलिटी (एआर) की सुविधाओं का इस्तेमाल करने के लिए, एआर को चालू करें.

अपने ऐप्लिकेशन को एआर की ज़रूरत या एआर (ऑगमेंटेड रिएलिटी) की ज़रूरत के तौर पर कॉन्फ़िगर करें

अलग-अलग डिवाइस पर जगह बचाने के लिए, एआर से जुड़ी सभी सुविधाएं Google Play Services for AR नाम के ऐप्लिकेशन में सेव की जाती हैं. Play Store इन सुविधाओं को अलग से अपडेट करता है. एआर की सुविधाओं का इस्तेमाल करने वाले Android ऐप्लिकेशन, ARCore SDK टूल की मदद से, Google Play Services for AR से संपर्क करते हैं. एआर सुविधाओं के साथ काम करने वाले ऐप्लिकेशन को दो तरीकों से कॉन्फ़िगर किया जा सकता है: एआर ज़रूरी है और एआर (ऑगमेंटेड रिएलिटी) ज़रूरी नहीं. इस कैटगरी से यह तय होता है कि ऐप्लिकेशन, Google Play Services for AR ऐप्लिकेशन के साथ कैसे इंटरैक्ट करता है.

एआर ज़रूरी है वाला ऐप्लिकेशन, ARCore के बिना काम नहीं करता. इसके लिए, ARCore की सुविधा वाले डिवाइस की ज़रूरत होती है, जिस पर Google Play Services for AR इंस्टॉल किया गया हो.

  • Google Play Store, ARCore के साथ काम करने वाले डिवाइसों पर सिर्फ़ एआर की ज़रूरी शर्तें पूरी करने वाले ऐप्लिकेशन उपलब्ध कराएगा.
  • जब उपयोगकर्ता एआर के लिए ज़रूरी ऐप्लिकेशन इंस्टॉल करते हैं, तो Google Play Store उनके डिवाइस पर Google Play Services for AR अपने-आप इंस्टॉल कर देगा. हालांकि, अगर Google Play Services for AR का पुराना वर्शन या उसे मैन्युअल तरीके से अनइंस्टॉल कर दिया गया है, तो आपके ऐप्लिकेशन को अब भी रनटाइम की अतिरिक्त जांच करनी होगी.

एआर (ऑगमेंटेड रिएलिटी) वैकल्पिक ऐप्लिकेशन, मौजूदा सुविधाओं को बेहतर बनाने के लिए ARCore का इस्तेमाल करता है. इसमें एआर की वैकल्पिक सुविधाएं हैं, जो सिर्फ़ उन डिवाइसों पर चालू होती हैं जिन पर ARCore काम करता है. साथ ही, जिनमें Google Play Services for AR इंस्टॉल किया गया है.

  • एआर (ऑगमेंटेड रिएलिटी) के वैकल्पिक ऐप्लिकेशन, उन डिवाइसों पर इंस्टॉल और चलाए जा सकते हैं जिनमें ARCore काम नहीं करता है.
  • जब उपयोगकर्ता एआर (ऑगमेंटेड रिएलिटी) वैकल्पिक ऐप्लिकेशन इंस्टॉल करते हैं, तो Google Play Store, डिवाइस पर Google Play Services for AR को अपने-आप इंस्टॉल नहीं करेगा.
एआर (ऑगमेंटेड रिएलिटी) ज़रूरी हैएआर (ऑगमेंटेड रिएलिटी) ज़रूरी नहीं है
एआर की सुविधा का इस्तेमाल बुनियादी सुविधाओं के लिए, आपके ऐप्लिकेशन में ARCore होना ज़रूरी है. ARCore, आपके ऐप्लिकेशन की सुविधाओं को बेहतर बनाता है. आपका ऐप्लिकेशन ARCore की सुविधा के बिना चल सकता है.
Play Store पर दिखने की सेटिंग Play Store में आपका ऐप्लिकेशन सिर्फ़ उन डिवाइसों के लिए मौजूद है जिनमें ARCore काम करता है. आपका ऐप्लिकेशन सामान्य लिस्टिंग प्रोसेस का पालन करता है.
Google Play Services for AR इंस्टॉल करने का तरीका Play Store आपके ऐप्लिकेशन के साथ-साथ, Google Play Services for AR भी इंस्टॉल करता है. आपका ऐप्लिकेशन, इन चीज़ों का इस्तेमाल करता है ArCoreApk.requestInstall() ARCore को डाउनलोड और इंस्टॉल करें.
Android minSdkVersion की ज़रूरी शर्तें Android 7.0 (एपीआई लेवल 24) Android 4.4 (एपीआई लेवल 19), हालांकि एआर की किसी भी सुविधा को चलाने के लिए, कम से कम Android 7.0 (एपीआई लेवल 24) की ज़रूरत होती है
ARCore के काम करने की सुविधा और इंस्टॉल की स्थिति के बारे में जानने के लिए, ArCoreApk.checkAvailability() या ArCoreApk.checkAvailabilityAsync() का इस्तेमाल करना ज़रूरी है
इस्तेमाल करना ज़रूरी है ArCoreApk.requestInstall() Google Play Services for AR इंस्टॉल करने के लिए

अगर आपको अपने ऐप्लिकेशन को एआर (ऑगमेंटेड रिएलिटी) ज़रूरी या एआर (ऑगमेंटेड रिएलिटी) वैकल्पिक बनाने के लिए, अपने AndroidManifest.xml को अपडेट करना है, तो यहां दी गई जानकारी को शामिल करें:

एआर (ऑगमेंटेड रिएलिटी) ज़रूरी है

<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>

एआर (ऑगमेंटेड रिएलिटी) ज़रूरी नहीं है

<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>

इसके बाद, अपने ऐप्लिकेशन के build.gradle में बदलाव करें, ताकि कम से कम 24 का minSdkVersion तय किया जा सके:

 android {
     defaultConfig {
         …
         minSdkVersion 24
     }
 }

बिल्ड डिपेंडेंसी जोड़ें

अपने Android Studio प्रोजेक्ट में ARCore जोड़ने के लिए, यह तरीका अपनाएं:

  1. पक्का करें कि आपके प्रोजेक्ट की build.gradle फ़ाइल में, Google की Maven रिपॉज़िटरी शामिल हो.

    allprojects {
        repositories {
            google()
            …
        }
    }
    
  2. अपने ऐप्लिकेशन की build.gradle फ़ाइल में डिपेंडेंसी के तौर पर नई ARCore लाइब्रेरी जोड़ें.

    dependencies {
        …
        implementation 'com.google.ar:core:1.33.0'
    }
    

रनटाइम की जांच करें

रनटाइम के दौरान, ये काम करें, ताकि यह पक्का किया जा सके कि आपके ऐप्लिकेशन पर एआर की सुविधाएं ठीक से काम करें.

देखें कि ARCore काम करता है या नहीं

मौजूदा डिवाइस पर ARCore काम करता है या नहीं, यह पता करने के लिए एआर ज़रूरी है और एआर वैकल्पिक ऐप्लिकेशन, दोनों को ArCoreApk.checkAvailability() या ArCoreApk.checkAvailabilityAsync() का इस्तेमाल करना चाहिए. जिन डिवाइसों पर ARCore काम नहीं करता है, उन पर ऐप्लिकेशन को एआर से जुड़ी सुविधा बंद कर देनी चाहिए और जुड़े हुए यूज़र इंटरफ़ेस (यूआई) एलिमेंट छिपा देने चाहिए.

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);
    }
  });
}
भले ही Google Play Services for AR आपके एआर के लिए ज़रूरी ऐप्लिकेशन के साथ इंस्टॉल किया गया हो, लेकिन काम न करने वाले डिवाइस का इस्तेमाल करने वाले लोग इसे किसी बाहरी स्रोत से इंस्टॉल कर सकते हैं. ArCoreApk.checkAvailability() या ArCoreApk.checkAvailabilityAsync() का इस्तेमाल करने पर, ARCore काम करता है या नहीं, यह पता करने से एक जैसा अनुभव मिलता है.

डिवाइस पर ARCore काम करता है या नहीं, यह पता करने के लिए ArCoreApk.checkAvailability() को नेटवर्क के संसाधनों से क्वेरी करनी पड़ सकती है. इस दौरान, यह UNKNOWN_CHECKING वापस आ जाएगा. इंतज़ार का समय और पॉप-इन कम करने के लिए, ऐप्लिकेशन को ArCoreApk.checkAvailability() को, लाइफ़ साइकल से पहले एक बार कॉल करना चाहिए, ताकि क्वेरी शुरू की जा सके. ऐसा करने के लिए, दिखाई गई वैल्यू को अनदेखा किया जा सकता है. ऐसा करने से, एआर में दिखने वाला यूज़र इंटरफ़ेस (यूआई) एलिमेंट दिखने पर, कैश मेमोरी में सेव किया गया नतीजा तुरंत उपलब्ध हो जाएगा.

देखें कि Google Play Services for AR इंस्टॉल है या नहीं

एआर ज़रूरी है और एआर वैकल्पिक ऐप्लिकेशन, दोनों का इस्तेमाल करना चाहिए ArCoreApk.requestInstall() ARCore सेशन बनाने से पहले, यह देख लें कि Google Play Services for AR का वर्शन इंस्टॉल है या नहीं. साथ ही, यह भी पक्का करें कि डिवाइस पर मौजूद ARCore प्रोफ़ाइल का सारा ज़रूरी डेटा डाउनलोड हो गया है.

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.
  }
  …
}

कैमरा ऐक्सेस करने की अनुमति मांगें

एआर (ऑगमेंटेड रिएलिटी) सेशन शुरू करने से पहले, एआर (ऑगमेंटेड रिएलिटी) ज़रूरी नहीं (ज़रूरी नहीं) और एआर (ऑगमेंटेड रिएलिटी) ज़रूरी ऐप्लिकेशन, दोनों को यह पक्का करना होगा कि कैमरा ऐक्सेस करने की अनुमति दी गई हो.

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;
  }

  …
}

आपकी एआर गतिविधि में भी 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();
  }
}

उपयोगकर्ता की निजता से जुड़ी ज़रूरी शर्तों का पालन करें

अपने ऐप्लिकेशन को Play Store पर पब्लिश करने के लिए, पक्का करें कि आपका ऐप्लिकेशन ARCore की नीतियों का पालन करता हो उपयोगकर्ता की निजता से जुड़ी ज़रूरी शर्तें.

आगे क्या होगा