আপনার Android অ্যাপে AR সক্ষম করুন

আপনার নতুন বা বিদ্যমান অ্যাপে অগমেন্টেড রিয়েলিটি ফিচার ব্যবহার করতে AR চালু করুন।

আপনার অ্যাপটিকে AR প্রয়োজনীয় বা AR ঐচ্ছিক হিসাবে কনফিগার করুন

পৃথক ডিভাইসে স্থান বাঁচাতে, সমস্ত AR বৈশিষ্ট্যগুলি Google Play Services for AR নামে একটি অ্যাপে সংরক্ষণ করা হয় যা প্লে স্টোর দ্বারা আলাদাভাবে আপডেট করা হয়। AR বৈশিষ্ট্যগুলি ব্যবহার করে এমন Android অ্যাপগুলি ARCore SDK ব্যবহার করে AR-এর জন্য Google Play পরিষেবাগুলির সাথে যোগাযোগ করে৷ AR বৈশিষ্ট্য সমর্থন করে এমন একটি অ্যাপ দুটি উপায়ে কনফিগার করা যেতে পারে: AR প্রয়োজনীয় এবং AR ঐচ্ছিক । এই উপাধিটি নির্ধারণ করে কিভাবে অ্যাপটি AR অ্যাপের জন্য Google Play পরিষেবার সাথে ইন্টারঅ্যাক্ট করে।

একটি AR প্রয়োজনীয় অ্যাপ ARCore ছাড়া কাজ করতে পারে না। এটির জন্য একটি ARCore সমর্থিত ডিভাইস প্রয়োজন যেটিতে AR এর জন্য Google Play পরিষেবা ইনস্টল করা আছে।

  • Google Play Store শুধুমাত্র ARCore সমর্থন করে এমন ডিভাইসগুলিতে AR প্রয়োজনীয় অ্যাপগুলি উপলব্ধ করবে।
  • যখন ব্যবহারকারীরা একটি AR প্রয়োজনীয় অ্যাপ ইনস্টল করেন, তখন Google Play Store স্বয়ংক্রিয়ভাবে তাদের ডিভাইসে AR-এর জন্য Google Play পরিষেবাগুলি ইনস্টল করে। যাইহোক, AR-এর জন্য Google Play Services পুরানো হয়ে গেলে বা ম্যানুয়ালি আনইনস্টল করা থাকলে আপনার অ্যাপকে এখনও অতিরিক্ত রানটাইম পরীক্ষা করতে হবে।

একটি AR ঐচ্ছিক অ্যাপ বিদ্যমান কার্যকারিতা উন্নত করতে ARCore ব্যবহার করে। এটিতে ঐচ্ছিক AR বৈশিষ্ট্য রয়েছে যা শুধুমাত্র ARCore সমর্থিত ডিভাইসগুলিতে সক্রিয় করা হয় যেগুলি AR-এর জন্য Google Play পরিষেবাগুলি ইনস্টল করেছে৷

  • AR ঐচ্ছিক অ্যাপগুলি ARCore সমর্থন করে না এমন ডিভাইসগুলিতে ইনস্টল এবং চালানো যেতে পারে।
  • ব্যবহারকারীরা যখন একটি AR ঐচ্ছিক অ্যাপ ইনস্টল করেন, তখন Google Play Store স্বয়ংক্রিয়ভাবে ডিভাইসে AR-এর জন্য Google Play Services ইনস্টল করবে না
এআর প্রয়োজন এআর ঐচ্ছিক
এআর ফিচার ব্যবহার মৌলিক কার্যকারিতার জন্য আপনার অ্যাপের ARCore প্রয়োজন। ARCore আপনার অ্যাপের কার্যকারিতা বাড়ায়। আপনার অ্যাপ ARCore সমর্থন ছাড়াই চলতে পারে।
প্লে স্টোরের দৃশ্যমানতা ARCore সমর্থন করে এমন ডিভাইসগুলিতে আপনার অ্যাপটি শুধুমাত্র Play Store-এ তালিকাভুক্ত। আপনার অ্যাপ স্বাভাবিক তালিকা পদ্ধতি অনুসরণ করে।
AR ইনস্টলেশন পদ্ধতির জন্য Google Play পরিষেবা Play Store আপনার অ্যাপের পাশাপাশি AR-এর জন্য Google Play পরিষেবা ইনস্টল করে। ARCore ডাউনলোড এবং ইনস্টল করতে আপনার অ্যাপ ArCoreApk.requestInstall() ব্যবহার করে।
অ্যান্ড্রয়েড minSdkVersion প্রয়োজনীয়তা Android 7.0 (API লেভেল 24) Android 7.0 (API লেভেল 24)
ARCore সমর্থন চেক করতে এবং স্থিতি ইনস্টল করতে অবশ্যই ArCoreApk.checkAvailability() বা ArCoreApk.checkAvailabilityAsync() ব্যবহার করতে হবে
AR এর জন্য Google Play পরিষেবাগুলি ইনস্টল করতে অবশ্যই ArCoreApk.requestInstall() ব্যবহার করতে হবে

আপনার অ্যাপকে AR প্রয়োজনীয় বা 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>

তারপরে, কমপক্ষে 24 এর একটি minSdkVersion নির্দিষ্ট করতে আপনার অ্যাপের build.gradle পরিবর্তন করুন:

 android {
     defaultConfig {
         …
         minSdkVersion 24
     }
 }

বিল্ড নির্ভরতা যোগ করুন

আপনার অ্যান্ড্রয়েড স্টুডিও প্রকল্পে ARCore যোগ করতে, নিম্নলিখিতগুলি করুন:

  1. আপনার প্রকল্পের build.gradle ফাইলে Google এর Maven সংগ্রহস্থল রয়েছে তা নিশ্চিত করুন৷

    allprojects {
        repositories {
            google()
            …
        }
    }
    
  2. আপনার অ্যাপের build.gradle ফাইলে নির্ভরতা হিসেবে সর্বশেষ ARCore লাইব্রেরি যোগ করুন।

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

রানটাইম চেক সঞ্চালন

রানটাইম চলাকালীন, আপনার অ্যাপে AR বৈশিষ্ট্যগুলি যাতে সুচারুভাবে চলে তা নিশ্চিত করতে নিম্নলিখিতগুলি করুন৷

ARCore সমর্থিত কিনা তা পরীক্ষা করুন

বর্তমান ডিভাইসটি ARCore সমর্থন করে কিনা তা নির্ধারণ করতে AR প্রয়োজনীয় এবং AR ঐচ্ছিক উভয় অ্যাপেরই ArCoreApk.checkAvailability() বা ArCoreApk.checkAvailabilityAsync() ব্যবহার করা উচিত। যে ডিভাইসগুলিতে ARCore সমর্থন করে না, অ্যাপগুলিকে AR-সম্পর্কিত কার্যকারিতা অক্ষম করা উচিত এবং সংশ্লিষ্ট UI উপাদানগুলি লুকানো উচিত।

কোটলিন

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

জাভা

@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 আপনার AR প্রয়োজনীয় অ্যাপের পাশাপাশি ইনস্টল করা আছে, অসমর্থিত ডিভাইসের ব্যবহারকারীরা এটি একটি বাহ্যিক উত্স থেকে ইনস্টল করতে পারে। ARCore সমর্থন পরীক্ষা করার জন্য ArCoreApk.checkAvailability() বা ArCoreApk.checkAvailabilityAsync() ব্যবহার করা একটি ধারাবাহিক অভিজ্ঞতা নিশ্চিত করে।

ডিভাইসটি ARCore সমর্থন করে কিনা তা নির্ধারণ করতে ArCoreApk.checkAvailability() নেটওয়ার্ক সংস্থানগুলি জিজ্ঞাসা করতে হতে পারে৷ এই সময়ের মধ্যে, এটি UNKNOWN_CHECKING ফিরে আসবে। অনুভূত লেটেন্সি এবং পপ-ইন কমাতে, ফিরে আসা মান উপেক্ষা করে অ্যাপগুলিকে তার জীবনচক্রের প্রথম দিকে একবার ArCoreApk.checkAvailability() কল করা উচিত। এইভাবে, একটি ক্যাশে ফলাফল অবিলম্বে উপলব্ধ হবে যখন একটি এআর-প্রবেশকারী UI উপাদান প্রদর্শিত হতে পারে।

AR এর জন্য Google Play Services ইনস্টল করা আছে কিনা তা পরীক্ষা করুন

AR প্রয়োজনীয় এবং AR ঐচ্ছিক উভয় অ্যাপকেই একটি ARCore সেশন তৈরি করার আগে অবশ্যই ArCoreApk.requestInstall() কল করতে হবে AR-এর জন্য Google Play Services-এর একটি সামঞ্জস্যপূর্ণ সংস্করণ ইনস্টল করা আছে কিনা (এখনও) এবং নিশ্চিত করতে যে সমস্ত প্রয়োজনীয় ARCore ডিভাইস প্রোফাইল ডেটা ডাউনলোড করা হয়েছে।

কোটলিন

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

জাভা

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

ক্যামেরা অনুমতির অনুরোধ করুন

AR ঐচ্ছিক এবং AR প্রয়োজনীয় অ্যাপ উভয়কেই নিশ্চিত করতে হবে যে AR সেশন তৈরি করার আগে ক্যামেরার অনুমতি দেওয়া হয়েছে।

কোটলিন

override fun onResume() {
  super.onResume()

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

  …
}

জাভা

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

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

  …
}

আপনার AR কার্যকলাপ অবশ্যই onRequestPermissionsResult() প্রয়োগ করতে হবে।

কোটলিন

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()
  }
}

জাভা

@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();
  }
}

ব্যবহারকারীর গোপনীয়তা প্রয়োজনীয়তা মেনে চলুন

প্লে স্টোরে আপনার অ্যাপ প্রকাশ করতে, নিশ্চিত করুন যে আপনার অ্যাপটি ARCore-এর ব্যবহারকারীর গোপনীয়তা প্রয়োজনীয়তা মেনে চলছে।

এরপর কি