Android: open camera device or attaching camera fails

0 votes
asked Feb 20, 2019 by gorilla3d (220 points)

I'm implementing EasyAR in my game engine (with Delphi DX). 
On Windows platform (x86 & x64) everything works fine, but on Android (test on Android 7 & Android 9) startup fails.

1) Initialization

1.1) I've linked the EasyAR.jar in my project and built an JNI unit with all classes and functions (automatically built by Java2Op tool).

1.2) Calling initialization method successfully

  // TJEngine is wrapper for "cn.easyar.Engine" class
  LEasyARCls := TJEngine.JavaClass;
  LBoolVal := LEasyARCls.initialize(TAndroidHelper.Activity, LEasyARKey);

  LBoolVal is TRUE

1.3) Requesting engine name and version works also => returns "EasyAR SDK Basic"
  TJEngine.JavaClass.versionString => returns "2.3.0"

2) Setting up camera and framestreamer

2.1) Creating camera device
  // TJeasyar_CameraDevice is wrapper for "cn.easyar.CameraDevice" class
  LCamera := TJeasyar_CameraDevice.Create(); => returns an interface
  LCamera.toString() => returns 'cn.easyar.CameraDevice@40b4c43'

2.2) Creating camera framestreamer
  // TJCameraFrameStreamer is wrapper for "cn.easyar.CameraFrameStreamer" class
  LFrameStreamer = TJCameraFrameStreamer.Create(); => return an interface
  LFrameStreamer.toString() => returns 'cn.easyar.CameraFrameStreamer@8de12c0'

2.3.a) 1st try: Attaching camera to framestreamer
  > interfaces are still available here
  LFrameStreamer.attachCamera(LCamera) => returns FALSE
2.3.b) 2nd try: Opening camera device
  > interfaces are still available here => returns FALSE
3) Versions and Settings
3.1) Permissions
  <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="26" />
  <uses-permission android:name="android.permission.CAMERA" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

3.2) Versions
  Android API Version: 26
  Android NDK Version: 17b_20.0.32429.4364
  JDK Version: jdk1.8.0_74
  IDE Version: Delphi DX 10.3

3.3) Test-Devices
  3.3.1) NVidia Shield Tablet K1, Android 7.0
  3.3.2) Nokia 7 Plus TA-1046, Android 9 00WW_3_39F

Do you have any ideas, what I am doing wrong? 

I'm really stucked at this point.

1 Answer

0 votes
answered Feb 21, 2019 by gorilla3d (220 points)


It was a permission problem! 

Since API v26 and Android 7+ were used for testing, permissions needed to be requested at runtime before using EasyAR.

Welcome to EasyAR SDK Q&A, where you can ask questions and receive answers from other members of the community.