From 2230c5ab996dde289bd77dcf075a2fb1120356b5 Mon Sep 17 00:00:00 2001 From: Keith Mayoral Date: Thu, 1 Feb 2024 05:33:26 -0800 Subject: [PATCH] Do not attempt to redirect to Play Store to install ARCore on unsupported devices (#322) * Fixed issue where unsupported AR Core devices still redirected to Play Store for attempt to install * Update ARCore.kt ArSession -> ARSession * Update ARCore.kt remove extra line at end of file --- .../java/io/github/sceneview/ar/ARCore.kt | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/arsceneview/src/main/java/io/github/sceneview/ar/ARCore.kt b/arsceneview/src/main/java/io/github/sceneview/ar/ARCore.kt index 85a4a99f..7ab7d66e 100644 --- a/arsceneview/src/main/java/io/github/sceneview/ar/ARCore.kt +++ b/arsceneview/src/main/java/io/github/sceneview/ar/ARCore.kt @@ -18,6 +18,7 @@ import com.google.ar.core.ArCoreApk.Availability import com.google.ar.core.Config import com.google.ar.core.Session import com.google.ar.core.TrackingFailureReason +import com.google.ar.core.exceptions.UnavailableDeviceNotCompatibleException import io.github.sceneview.ar.arcore.ARSession /** @@ -213,16 +214,39 @@ class ARCore( }) } + /** + * Checks if ARCore is already installed or attempts to request an install otherwise. + * + * @param activity The current activity which will be paused if we request an install + * @param installRequested Should be true the first time this is called, and false when we + * resume from the previous install attempt + * @throws UnavailableDeviceNotCompatibleException if the device does not support ARCore + * @return true if ARCore is already installed + */ fun checkInstall(activity: ComponentActivity, installRequested: Boolean): Boolean { // Request installation if necessary return isInstalled(activity) || !install(activity, installRequested) } - /** Check to see we have the necessary permissions for this app. */ + /** Check to see we have the necessary permissions for this app. */ fun isInstalled(context: Context) = ArCoreApk.getInstance().checkAvailability(context) == Availability.SUPPORTED_INSTALLED + /** Check to see if we're on a device where ARCore can be installed */ + fun canBeInstalled(context: Context): Boolean { + val availability = ArCoreApk.getInstance().checkAvailability(context) + return availability == Availability.SUPPORTED_APK_TOO_OLD || availability == Availability.SUPPORTED_NOT_INSTALLED + } + + /** + * Returns true if we attempted to request an install. + * + * @throws UnavailableDeviceNotCompatibleException if the device does not support ARCore + */ fun install(activity: ComponentActivity, installRequested: Boolean): Boolean { + if (!canBeInstalled(activity)) { + throw UnavailableDeviceNotCompatibleException() + } return ArCoreApk.getInstance().requestInstall( activity, !installRequested @@ -245,4 +269,4 @@ fun TrackingFailureReason.getDescription(context: Context) = when (this) { TrackingFailureReason.INSUFFICIENT_FEATURES -> context.getString(R.string.sceneview_insufficient_features_message) TrackingFailureReason.CAMERA_UNAVAILABLE -> context.getString(R.string.sceneview_camera_unavailable_message) else -> context.getString(R.string.sceneview_unknown_tracking_failure, this) -} \ No newline at end of file +}