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

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

अपने ऐप्लिकेशन को एआर की सुविधा के साथ काम करने वाला या एआर की सुविधा के बिना काम करने वाला ऐप्लिकेशन के तौर पर कॉन्फ़िगर करना

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

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

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

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

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

अपने ऐप्लिकेशन को एआर की सुविधा ज़रूरी है या एआर की सुविधा वैकल्पिक है के तौर पर सेट करने के लिए, AndroidManifest.xml को अपडेट करें. इसमें ये एंट्री शामिल करें:

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>

एआर की सुविधा ज़रूरी नहीं है

<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 की सुविधा उपलब्ध है या नहीं

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

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

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

AR Required और AR Optional, दोनों तरह के ऐप्लिकेशन को ARCore सेशन बनाने से पहले ArCoreApk.requestInstall() का इस्तेमाल करना होगा. इससे यह पता चलेगा कि 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 की उपयोगकर्ता की निजता से जुड़ी ज़रूरी शर्तों का पालन करता हो.

अब क्या होगा