Skip to content

orbbec/OrbbecSDK-Android-Wrapper

Repository files navigation

Quick start

Important

Welcome to the Android wrapper . Before you begin using this version of Android wrapper , it's crucial to check the following device support list to verify the compatibility.

Here is the device support list of main branch (v1.x) and v2-main branch (v2.x):

Product Series Product Branch main Branch v2-main
Gemini 330 Gemini 335 full maintenance recommended for new designs
Gemini 336 full maintenance recommended for new designs
Gemini 330 full maintenance recommended for new designs
Gemini 335L full maintenance recommended for new designs
Gemini 336L full maintenance recommended for new designs
Gemini 330L full maintenance recommended for new designs
Gemini 2 Gemini 2 full maintenance recommended for new designs
Gemini 2 L full maintenance recommended for new designs
Gemini 210 not supported recommended for new designs
Gemini 215 not supported recommended for new designs
Gemini 2 XL recommended for new designs to be supported
Astra Astra 2 full maintenance recommended for new designs
Astra+ limited maintenance not supported
Astra Pro Plus limited maintenance not supported
Astra Mini Astra Mini Pro full maintenance not supported

Note: If you do not find your device, please contact our FAE or sales representative for help.

Definition:

  1. recommended for new designs: we will provide full supports with new features, bug fix and performance optimization;
  2. full maintenance: we will provide bug fix support;
  3. limited maintenance: we will provide critical bug fix support;
  4. not supported: we will not support specific device in this version;
  5. to be supported: we will add support in the near future.

download source

git clone https://github.com/orbbec/OrbbecSDK-Android-Wrapper.git

import project

  1. Open Android studio
  2. Menu: File --> open, and select project directory
  3. Click Ok button
  4. wait gradle sync complete

run example

build example

Main UI

Click 'DepthViewer' to show depth sensor stream.

DepthViewer

Build Tools

Android studio

Android studio Giraffe | 2022.3.1 Patch 1 download link Android studio

NDK

version: 21.4.7075529

CMake

version: 3.18.1

gradle

gradle/wrapper/gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip

gradle pulgins

build.gradle

plugins {
id 'com.android.application' version '8.1.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
    id 'com.android.library' version '8.1.0' apply false
}

library and example

sensorsdk

Orbbec basic sdk implementation with c & cpp, android wrapper import sensorsdk as so.

so files

path: obsensor_jni/libs

include headers

path: obsensor_jni/src/main/cpp/sensorsdk

Note: To short include path in native code, module of 'obsensor_jni' import as path 'obsensor_jni/src/main/cpp/sensorsdk/include/libobsensor'

obsensor_jni

Android wrapper implementation with jni which is forward or transfer data between java and native sensorsdk.

Support android version

  • Test on the Android 13
  • Note: If using Android 10, set targetSdk to 27
minSdk 24
//noinspection ExpiredTargetSdkVersion
targetSdk 27

targetSdkVersion 27 to fixed bug 'Android 10 Devices Do NOT Support USB Camera Connection' which fixed on android 11. [reference 01] Android 10 sdk28 usb camera device class bug.

[reference 02] Android 10 Devices Do NOT Support USB Camera Connection.

example

Example of sensorsdk android wrapper

Support orbbec device

OrbbecSDK:v1.10.3 Support device list (firmware version):

SDK version Product Minimal Firmware version
v1.10.3 Gemini 335 1.2.20
Gemini 335L 1.2.20
Gemini 336 1.2.20
Gemini 336L 1.2.20
Gemini 2 XL Obox: V1.2.5 VL:1.4.54
Astra 2 2.8.20
Gemini 2 L 1.4.32
Gemini 2 1.4.60
Astra+ 1.0.19
Femto 1.6.7
Femto W 1.1.8
DaBai 2436
DaBai DCW 2460
DaBai DW 2606
Astra Mini Pro 1007
Gemini E 3460
Gemini E Lite 3606
Gemini 3018
Astra Mini S Pro 1005

Simple code of open depth stream

Create OBContext global member to manager attach devices

// Application hold only one OBContext instance.
private OBContext mOBContext;
private Object mCurrentDeviceLock = new Object();
private Device mCurrentDevice;
private DeviceInfo mCurrentDeviceInfo;

Initialize OBContext with DeviceChangedCallback

mOBContext = new OBContext(getApplicationContext(), new DeviceChangedCallback() {
   @Override
   public void onDeviceAttach(DeviceList deviceList) {
        try {
            mDevice = deviceList.getDevice(0);
            deviceList.close();
            // do something
            mDevice.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
   }

   @Override
   public void onDeviceDetach(DeviceList deviceList) {
         try {
            if (null != mCurrentDevice){
                int deviceCount=deviceList.getDeviceCount();
                    for(int i=0;i<deviceCount; i++){
                        String uid=deviceList.getUid();
                        if(null!=mCurrentDeviceInfo&&mCurrentDeviceInfo.getUid().equals(uid)){
                            // handle device disconnection
                            // do something

                            Log.d("Orbbec","Device disconnection. name: "+mCurrentDeviceInfo.getName()+", uid: "+mCurrentDeviceInfo.getUid());
                            mCurrentDevice.close();
                            mCurrentDevice=null;
                        }
                    }
            }
         } catch (Exception e) {
            e.printStackTrace();
         } finally {
            deviceList.close();
        }
   }
});

Define Pipeline and Device

private Pipeline mPipeline;

Start Depth stream

try {
   mPipeline = new Pipeline(mCurrentDevice);

   StreamProfileList depthProfileList = mPipeline.getStreamProfileList(SensorType.DEPTH);
   if (null != depthProfileList) {
      depthProfileList.close();
      return;
   }
   StreamProfile streamProfile = depthProfileList.getStreamProfile(0);
   Config config = new Config();
   config.enableStream(streamProfile);
   streamProfile.close();
   depthProfileList.close();

   mPipeline.start(config, new FrameSetCallback() {
      public void onFrameSet(FrameSet frameSet) {
         DepthFrame depthFrame = frameSet.getDepthFrame()
         if (null != depthFrame) {
            Log.d("Orbbec", "onFrameSet depthFrame index: " + depthFrame.getFrameIndex() + ", timeStamp: " + depthFrame.getTimeStamp());

            // do Render

            depthFrame.close();
         }
      }
   });
   config.close();
} catch (OBException e) {
   e.printStackTrace();
}

Stop stream

try {
   mPipeline.stop();
   mPipeline.close();
   mPipeline = null;
} catch (OBException e) {
   e.printStackTrace();
}

QA

LintModelSeverity has been compiled by a more recent version of the Java

An exception occurred applying plugin request [id: 'com.android.application']
> Failed to apply plugin 'com.android.internal.application'.
   > Could not create an instance of type com.android.build.gradle.internal.dsl.ApplicationExtensionImpl$AgpDecorated.
      > Could not create an instance of type com.android.build.gradle.internal.dsl.LintImpl$AgpDecorated.
         > Could not generate a decorated class for type LintImpl$AgpDecorated.
            > com/android/tools/lint/model/LintModelSeverity has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

Reason: AGP(android gradle plugin) is v8.1.0, need jdk 17, Please update android studio to new version, and check gradle jdk version. Android studio --> File --> Settings --> Build,Execution,Deployment --> Build Tools --> Gradle, check Gradle Projects -> Gradle JDK

reference: https://developer.android.com/studio/releases#android_gradle_plugin_and_android_studio_compatibility

https://developer.android.com/build/releases/gradle-plugin