Java源码示例:com.google.ar.core.ArCoreApk
示例1
public static int isSupported(Context context) {
if (!ARCheck.isFrameworkPresent()) {
return AR_CHECK_NOT_SUPPORTED;
}
if (planeFindingModes == null) {
planeFindingModes = Config.PlaneFindingMode.values();
lightEstimationModes = Config.LightEstimationMode.values();
updateModes = Config.UpdateMode.values();
}
ArCoreApk.Availability availability = ArCoreApk.getInstance().checkAvailability(context);
if (availability.isTransient()) {
return AR_CHECK_TRANSIENT;
}
// ARCore APK might be side loaded onto the device. In that case, the availability check
// will return SUPPORTED_INSTALLED but session creation will still fail. We try creating a
// session here, just to make sure the device supports ARCore.
// Anything other than SUPPORTED_INSTALLED is considered unsupported in our case, because
// we don't want to prompt an install dialog before showing an ad.
if (availability == ArCoreApk.Availability.SUPPORTED_INSTALLED) {
try {
//noinspection unused
Session session = new Session(context);
} catch (FatalException | UnavailableException e) {
return AR_CHECK_NOT_SUPPORTED;
} catch (SecurityException ignored) {
// Session creation failed because we don't have camera permission yet.
// This can be ignored.
}
return AR_CHECK_SUPPORTED;
}
return AR_CHECK_NOT_SUPPORTED;
}
示例2
@Override
protected void onResume() {
super.onResume();
// Check if ARCore is installed/up-to-date
int message = -1;
Exception exception = null;
try {
switch (ArCoreApk.getInstance()
.requestInstall(this, mUserRequestedARCoreInstall)) {
case INSTALLED:
// Success.
break;
case INSTALL_REQUESTED:
// Ensures next invocation of requestInstall() will either return
// INSTALLED or throw an exception.
mUserRequestedARCoreInstall = false;
// at this point, the activity is paused and user will go through
// installation process
return;
}
} catch (Exception e) {
message = getARCoreInstallErrorMessage(e);
exception = e;
}
// display possible ARCore error to user
if (message >= 0) {
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
Log.e(TAG, "Exception installing ARCore", exception);
finish();
return;
}
// when user comes back from system settings, send them to Draw AR if they
// gave us the permissions
if ((mPermissionRationaleDialog == null || !mPermissionRationaleDialog.isShowing())
&& !PermissionHelper.hasRequiredPermissions(this)) {
PermissionHelper.requestRequiredPermissions(this, false);
} else if (PermissionHelper.hasRequiredPermissions(this)) {
startDrawARDelayed();
}
}
示例3
public static boolean isVelocitySensorAvailable(Context appContext) {
if (Flags.showVelocityTrackerOption()) {
ArCoreApk.Availability availability = null;
try {
// Calling checkAvailability() will determine if ARCore is supported on this device.
availability = ArCoreApk.getInstance().checkAvailability(appContext);
} catch (NullPointerException e) {
// Unclear why NPE is happening in ArCoreApkImpl.checkInstallActivity
// TODO(b/141910242): Investigate why this NPE is happening
if (Log.isLoggable(TAG, Log.ERROR)) {
Log.e(TAG, "NPE initiating ARCore check", e);
}
}
if (availability != null) {
// Transient means this state is temporary and we should re-check availability soon.
if (availability.isTransient()) {
// TODO (b/139126555): update this method to re-query if availability is transient
return false;
}
// Check that the device is compatible with Sceneform.
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
Log.e(TAG, "Sceneform requires Android N or later");
return false;
}
// Do a runtime check for the OpenGL level available at runtime.
String openGlVersionString =
((ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE))
.getDeviceConfigurationInfo()
.getGlEsVersion();
if (Double.parseDouble(openGlVersionString) < MIN_OPENGL_VERSION) {
Log.e(TAG, "Sceneform requires OpenGL ES 3.0 or later");
return false;
}
return availability.isSupported();
}
}
return false;
}