本文介绍了ArCoreApk 检查可用性不适用于 api 30的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ArCoreApk 检查可用性在 API 级别 29 及以下返回 true,但在 30 时返回 false.有任何想法吗?
ArCoreApk check availability returns true on API Level 29 and below but false on 30. Any ideas?
fun checkArCoreAvailability(context: Context) {
var message: String? = null
var isArCoreInstalled = false
try {
when (ArCoreApk.getInstance().checkAvailability(context)) {
ArCoreApk.Availability.UNKNOWN_ERROR -> {
message = "This device does not support AR, starting normal session"
}
ArCoreApk.Availability.UNKNOWN_CHECKING -> {
message = "This device does not support AR, starting normal session"
Handler().postDelayed({
checkArCoreAvailability(context)
}, 250)
}
ArCoreApk.Availability.UNKNOWN_TIMED_OUT -> {
message = "This device does not support AR, starting normal session"
}
ArCoreApk.Availability.UNSUPPORTED_DEVICE_NOT_CAPABLE -> {
message = "This device does not support AR, starting normal session"
}
ArCoreApk.Availability.SUPPORTED_NOT_INSTALLED -> {
message = "Please install ArCore to use pinned annotations"
}
ArCoreApk.Availability.SUPPORTED_APK_TOO_OLD -> {
message = "Please update ArCore to use pinned annotations"
}
ArCoreApk.Availability.SUPPORTED_INSTALLED -> {
isArCoreInstalled = true
message = "Starting AR Session"
}
null -> {
message = "This device does not support AR, starting normal session"
}
}
} catch (e: UnavailableArcoreNotInstalledException) {
message = "Please install ARCore to use pinned annotations"
} catch (e: UnavailableUserDeclinedInstallationException) {
message = "Please install ARCore to use pinned annotations"
} catch (e: UnavailableApkTooOldException) {
message = "Please update ARCore to use pinned annotations"
} catch (e: UnavailableSdkTooOldException) {
message = "Please update this app"
} catch (e: java.lang.Exception) {
message = "This device does not support AR, starting normal session"
}
Toast.makeText(context, message, Toast.LENGTH_LONG).show()
}
推荐答案
尝试向清单中添加适当的查询项:
Try to add appropriate query item to your manifest:
<manifest>
<queries>
<package android:name="com.google.ar.core" />
</queries>
</manifest>
这篇关于ArCoreApk 检查可用性不适用于 api 30的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!