अपने नए या मौजूदा ऐप्लिकेशन में ऑगमेंटेड रिएलिटी (एआर) की सुविधाओं का इस्तेमाल करने के लिए, एआर को चालू करें.
अपने ऐप्लिकेशन को एआर की ज़रूरत है या एआर ज़रूरी नहीं है, इस हिसाब से कॉन्फ़िगर करना
अलग-अलग डिवाइसों में जगह बचाने के लिए, एआर की सभी सुविधाओं को 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 भी इंस्टॉल करता है. | आपका ऐप्लिकेशन, 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
को अपडेट करें. इसके लिए, इन एंट्री को शामिल करें:
<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
}
}
बिल्ड डिपेंडेंसी जोड़ना
पक्का करें कि आपके प्रोजेक्ट की
build.gradle
फ़ाइल में Google की Maven रिपॉज़िटरी शामिल हो.allprojects { repositories { google() … } }
ARCore AAR फ़ाइल से शामिल नेटिव लाइब्रेरी निकालने के लिए, अपने मॉड्यूल की
build.gradle
फ़ाइल में कस्टम टास्क जोड़ें. इस तरह, उन्हें सीधे C या C++ प्रोजेक्ट में रेफ़र किया जा सकता है.app/build
डायरेक्ट्री में, उस डायरेक्ट्री के लिए वैरिएबल तय करें जहां नेटिव लाइब्रेरी निकाली जाएंगी.डेटा और डेटा निकालने के टास्क को सेव करने के लिए, Gradle कॉन्फ़िगरेशन बनाएं.
/* The ARCore AAR library contains native shared libraries that are extracted before building to a temporary directory. */ def arcore_libpath = "${buildDir}/arcore-native" // Create a configuration to mark which aars to extract .so files from configurations { natives }
AAR फ़ाइल से नेटिव लाइब्रेरी कॉपी करने के लिए टास्क बनाएं और उसे बिल्ड डिपेंडेंसी में जोड़ें.
// Extracts the shared libraries from AARs in the native configuration // so that NDK builds can access these libraries. task extractNativeLibraries() { // Extract every time. outputs.upToDateWhen { false } doFirst { configurations.natives.files.each { f -> copy { from zipTree(f) into arcore_libpath include "jni/**/*" } } } } tasks.whenTaskAdded { task-> if (task.name.contains("external") && !task.name.contains("Clean")) { task.dependsOn(extractNativeLibraries) } }
बाहरी बिल्ड टूल को जगहों की जानकारी देने के लिए, नेटिव बिल्ड फ़्लैग कॉन्फ़िगर करें.
// From the sample app. externalNativeBuild { cmake { cppFlags "-std=c++11", "-Wall" arguments "-DANDROID_STL=c++_static", "-DARCORE_LIBPATH=${arcore_libpath}/jni", "-DARCORE_INCLUDE=${project.rootDir}/../../libraries/include" } }
Java और नेटिव, दोनों लाइब्रेरी के लिए डिपेंडेंसी जोड़ें.
dependencies { ... // Add Java and native dependencies to the ARCore library. implementation 'com.google.ar:core:1.33.0' natives 'com.google.ar:core:1.33.0' ... }
CMakeLists.txt
में नेटिव लाइब्रेरी का रेफ़रंस दें.# Import the ARCore library. add_library(arcore SHARED IMPORTED) set_target_properties(arcore PROPERTIES IMPORTED_LOCATION ${ARCORE_LIBPATH}/${ANDROID_ABI}/libarcore_sdk_c.so INTERFACE_INCLUDE_DIRECTORIES ${ARCORE_INCLUDE} )
रनटाइम के दौरान होने वाली जांचें करना
रनटाइम के दौरान, यह पक्का करने के लिए कि आपके ऐप्लिकेशन पर एआर की सुविधाएं आसानी से काम करें, ये काम करें.
देखें कि आपके डिवाइस पर ARCore काम करता है या नहीं
AR की ज़रूरत वाले और AR की ज़रूरत नहीं वाले, दोनों ऐप्लिकेशन कोArCoreApk_checkAvailability()
या ArCoreApk_checkAvailabilityAsync()
का इस्तेमाल करके यह तय करना चाहिए कि मौजूदा डिवाइस पर ARCore काम करता है या नहीं. जिन डिवाइसों पर ARCore काम नहीं करता उन पर, ऐप्लिकेशन को एआर से जुड़ी सुविधाएं बंद करनी चाहिए और उससे जुड़े यूज़र इंटरफ़ेस (यूआई) एलिमेंट छिपाने चाहिए.
Android NDK ऐप्लिकेशन, Java ArCoreApk
क्लास का इस्तेमाल करके, नेटिव C ARCore Session API में इंस्टॉलेशन को मैनेज कर सकता है और यह देख सकता है कि ऐप्लिकेशन काम करता है या नहीं. आपके ऐप्लिकेशन के स्ट्रक्चर के आधार पर, यह ArCoreApk_
फ़ंक्शन का इस्तेमाल करने से आसान हो सकता है. इसकी वजह यह है कि इसमें गड़बड़ी को ठीक करने और यूज़र इंटरफ़ेस इंटरैक्शन की ज़्यादा संख्या शामिल होती है.
void maybeEnableArButton(JNIEnv env, jobject context) {
// Likely called from Activity.onCreate() of an activity with AR buttons.
ArAvailability availability
ArCoreApk_checkAvailability(env, context, &availability);
if (availability == AR_AVAILABILITY_UNKNOWN_CHECKING) {
// Set a timer to call maybeEnableArButton() again after about 200ms.
}
if (availability == AR_AVAILABILITY_SUPPORTED_NOT_INSTALLED ||
availability == AR_AVAILABILITY_SUPPORTED_APK_TOO_OLD ||
availability == AR_AVAILABILITY_SUPPORTED_INSTALLED) {
// Show or enable the AR button.
} else {
// Hide or disable the AR button.
}
}
ArCoreApk_checkAvailability()
या ArCoreApk_checkAvailabilityAsync()
का इस्तेमाल करें. इससे यह पक्का किया जा सकता है कि आपको एक जैसा अनुभव मिले.
ArCoreApk_checkAvailability()
को नेटवर्क संसाधनों से क्वेरी करने की ज़रूरत पड़ सकती है, ताकि यह पता लगाया जा सके कि डिवाइस पर ARCore काम करता है या नहीं. इस दौरान, यह AR_AVAILABILITY_UNKNOWN_CHECKING
दिखाएगा. इंतज़ार का अनुमानित समय और पॉप-इन को कम करने के लिए, ऐप्लिकेशन को अपने लाइफ़ साइकल की शुरुआत में एक बार ArCoreApk_checkAvailability()
को कॉल करना चाहिए, ताकि क्वेरी शुरू की जा सके. साथ ही, रिटर्न की गई वैल्यू को अनदेखा किया जा सके. इस तरह, जब एआर में प्रवेश करने वाला यूआई एलिमेंट दिख सकता है, तब कैश मेमोरी में सेव किया गया नतीजा तुरंत उपलब्ध हो जाएगा.
देखें कि Google Play Services for AR इंस्टॉल है या नहीं
एआर की ज़रूरत वाले और एआर की ज़रूरत नहीं वाले, दोनों ऐप्लिकेशन को ARCore सेशन बनाने से पहले,
ArCoreApk.requestInstall()
का इस्तेमाल करना होगा. इससे यह पता चलता है कि Google Play Services for AR का काम करने वाला वर्शन (अब भी) इंस्टॉल है या नहीं. साथ ही, यह भी पक्का किया जा सकता है कि ARCore डिवाइस प्रोफ़ाइल का ज़रूरी डेटा डाउनलोड हो गया है या नहीं.
// Tracks if an installation request has already been triggered.
bool install_requested_;
void nativeOnCreate() {
// Do other setup here.
install_requested_ = false;
}
void nativeOnResume(JNIEnv env, jobject activity) {
if (ar_session_ == null) {
bool user_requested_install = !install_requested_;
ArInstallStatus install_status;
// Ensure that Google Play Services for AR and ARCore device profile data are
// installed and up to date.
ArStatus error = ArCoreApk_requestInstall(
env, activity, user_requested_install, &install_status);
if (error != AR_SUCCESS) {
// Inform user of error.
return;
}
switch (install_status) {
case AR_INSTALL_STATUS_INSTALLED:
break;
case AR_INSTALL_STATUS_INSTALL_REQUESTED:
// When this method returns AR_INSTALL_STATUS_INSTALL_REQUESTED:
// 1. This activity will be paused.
// 2. The user is prompted 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. This activity is resumed. The next invocation of
// ArCoreApk_requestInstall() will either return
// AR_INSTALL_STATUS_INSTALLED or throw an exception if the
// installation or update did not succeed.
install_requested_ = true;
return;
}
// Request camera permissions.
error = ArSession_create(env, context, &ar_session_);
if (error != AR_SUCCESS) {
// Inform user of error.
return;
}
// Configure the ARCore session.
}
// Normal onResume behavior.
}
उपयोगकर्ता की निजता से जुड़ी ज़रूरी शर्तों का पालन करना
अपने ऐप्लिकेशन को Play Store पर पब्लिश करने के लिए, पक्का करें कि आपका ऐप्लिकेशन, ARCore की उपयोगकर्ता की निजता से जुड़ी ज़रूरी शर्तों का पालन करता हो.
अब क्या होगा
- ARCore सेशन को कॉन्फ़िगर करने का तरीका जानें.