简体   繁体   English

如何知道给定设备是否在 ARCore 支持的设备列表中?

[英]How to know if a given device is in the list of supported devices for ARCore?


I am using Google CoreAR package in my React-Native app for AR support.我在我的React-Native应用程序中使用Google CoreAR package来支持 AR。 There are some devices which support AR and some not.有些设备支持 AR,有些则不支持。 I am getting error while I run the application in non-supported devices.在不受支持的设备上运行应用程序时出现错误。 I want to render a message instead showing error on the screen.我想呈现一条消息而不是在屏幕上显示错误。 For this Google CoreAR package is providing the solution which is not working for me.为此, 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);
  }
}

The problem with above code snippet is that availability.isSupported() is always returning true and that's why else part of code is not running.上面代码片段的问题是availability.isSupported()总是返回true ,这就是为什么其他部分代码没有运行的原因。 Can you guys please help me with this?你们能帮我解决这个问题吗? Thank you.谢谢你。

I found solution for this problem.我找到了解决这个问题的方法。 ArCoreApk.Availability has some methods which can be used. ArCoreApk.Availability有一些方法可以使用。 You can find these methods in the documentation .您可以在文档中找到这些方法。 The method ArCoreApk.Availability return either SUPPORTED_INSTALLED or SUPPORTED_NOT_INSTALLED depending on device support. ArCoreApk.Availability方法根据设备支持返回SUPPORTED_INSTALLEDSUPPORTED_NOT_INSTALLED So based on this return value we can do the stuff.所以基于这个返回值我们可以做这些事情。

I did like this.我确实喜欢这个。

@ReactMethod
  public ArCoreApk.Availability getSupport(){

    ArCoreApk.Availability availability = ArCoreApk.getInstance().checkAvailability(this.getReactApplicationContext());

    return availability.name();
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM