[英]How to know if a given device is in the list of supported devices for ARCore?
我在我的React-Native
應用程序中使用Google CoreAR package來支持 AR。 有些設備支持 AR,有些則不支持。 在不受支持的設備上運行應用程序時出現錯誤。 我想呈現一條消息而不是在屏幕上顯示錯誤。 為此, Google CoreAR
package 提供了對我不起作用的解決方案。
void maybeEnableArButton() {
ArCoreApk.Availability availability = ArCoreApk.getInstance().checkAvailability(this);
if (availability.isTransient()) {
// Continue to query availability at 5Hz while compatibility is checked in the background.
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
maybeEnableArButton();
}
}, 200);
}
if (availability.isSupported()) {
mArButton.setVisibility(View.VISIBLE);
mArButton.setEnabled(true);
} else { // The device is unsupported or unknown.
mArButton.setVisibility(View.INVISIBLE);
mArButton.setEnabled(false);
}
}
上面代碼片段的問題是availability.isSupported()
總是返回true
,這就是為什么其他部分代碼沒有運行的原因。 你們能幫我解決這個問題嗎? 謝謝你。
我找到了解決這個問題的方法。 ArCoreApk.Availability
有一些方法可以使用。 您可以在文檔中找到這些方法。 ArCoreApk.Availability
方法根據設備支持返回SUPPORTED_INSTALLED
或SUPPORTED_NOT_INSTALLED
。 所以基於這個返回值我們可以做這些事情。
我確實喜歡這個。
@ReactMethod
public ArCoreApk.Availability getSupport(){
ArCoreApk.Availability availability = ArCoreApk.getInstance().checkAvailability(this.getReactApplicationContext());
return availability.name();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.