android - ArCoreApk 检查可用性不适用于 api 30

标签 android arcore

ArCoreApk 检查可用性在 API 级别 29 及以下返回 true 但在 30 返回 false。有什么想法吗?

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

最佳答案

尝试向 list 中添加适当的查询项:

<manifest>
    <queries>
        <package android:name="com.google.ar.core" />
    </queries>
</manifest>

关于android - ArCoreApk 检查可用性不适用于 api 30,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68365368/

相关文章:

java - android 上的 nd4j 后端 RuntimeException

java - Android jni 和 opencv 运行时无法加载库

android - 在 Android 上将图像与视频流结合起来

java - 从 URL 检索 JSON 时,Android Bad Request IOException

Android 编辑文本和按钮小部件在平板电脑中显得模糊

Android:如何缩小View的可点击区域?

java - ArCore 成功楼层查找

java - ARCore TransformableNode 拖动后将 localPosition 设置为 [x=0.0, y=0.0, z=0.0]

android - 使用 ArCore 时是否可以捕获高分辨率图像?

java - 如何在 ARCore 中提高预览相机质量