Skip to content

Commit

Permalink
Do not attempt to redirect to Play Store to install ARCore on unsuppo…
Browse files Browse the repository at this point in the history
…rted 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
  • Loading branch information
kmayoral authored Feb 1, 2024
1 parent a0cbfa2 commit 2230c5a
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions arsceneview/src/main/java/io/github/sceneview/ar/ARCore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
}

0 comments on commit 2230c5a

Please sign in to comment.