NhlanhlaNkosi
NhlanhlaNkosi

Reputation: 613

Using sceneform SDK in android studio, to create a 3d viewer activity on unsupported devices

I'm using sceneform to create an AR app in Android Studio. Everything works as expected on supported devices. However on unsupported devices i want the user of the app to alternatively view the 3d object / model without the augmented reality feature like in Google expeditions Expeditions App. How can i achieve this?

Upvotes: 0

Views: 267

Answers (1)

Csaba Toth
Csaba Toth

Reputation: 10729

The solution to this might not be simple and may require two side-by-side applications. I'll give a high level view of what I think. It'd be good to see what you have right now, post a git repo link you have. But I assume that somewhere along the line you have an AR view Fragment in your code. That fragment contains some compatibility check, like so:

  @Override
  public void onAttach(Context context) {
    super.onAttach(context);

    // Check for Sceneform being supported on this device.  This check will be integrated into
    // Sceneform eventually.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
      Log.e(TAG, "Sceneform requires Android N or later");
      Snackbar.make(getActivity().findViewById(android.R.id.content),
              "Sceneform requires Android N or later",
              Snackbar.LENGTH_LONG).setAction("Action", null).show();
    }

    String openGlVersionString =
        ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE))
            .getDeviceConfigurationInfo()
            .getGlEsVersion();
    if (Double.parseDouble(openGlVersionString) < MIN_OPENGL_VERSION) {
      Log.e(TAG, "Sceneform requires OpenGL ES 3.0 or later");
      Snackbar.make(getActivity().findViewById(android.R.id.content),
              "Sceneform requires OpenGL ES 3.0 or later",
              Snackbar.LENGTH_LONG).setAction("Action", null).show();
    }
  }

Here you can revert to a non AR solution. The problem is that normally this point is too late to revert back to a compatible view for unsupported devices. If you look at your AndroidManifest.xml, you see two entries related to AR there:

<uses-feature android:name="android.hardware.camera.ar" android:required="true"/>

and

<meta-data android:name="com.google.ar.core" android:value="required" />

These two entries are picked up by the Google Play Store system, and it automatically won't offer the app for devices which are not compatible. There are two ways here you can gravitate towards:

  1. Remove the Android manifest entries cited above, but then you must test the compatibility in the code. In this case you'd add another fragment to you ActivityFrame layout, that would be the compatibility view. Place the feature test codes and shuttle the viewer to the proper fragment (AR Fragment for AR devices, 3D for non compatible).
  2. You develop two applications. One is 3D compatible one, that's what an everyday user would start. This application would also contain feature testing code like the previous option, but this would start an (Android Instant app)[https://www.raywenderlich.com/9519-instant-apps-getting-started] which is ARCore capable once the AR features are detected. This could provide a seamless transition, and once it started the AR compatible devices could stay with that AR app. Since there would be two separate apps I'd try to keep common codebase in a library and share it between the two apps to avoid code duplication.

Disclaimer: these are concepts and I never tried to spawn an AR Core instant app.

Upvotes: 0

Related Questions