Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23795] Hyperloop - Android: Using Camera2 API CameraManager not working

GitHub Issuen/a
TypeBug
Priorityn/a
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsHyperloop
Labelsandroid, camera, engTriage, hyperloop
ReporterMichael Gangolf
AssigneeJan Vennemann
Created2016-08-19T18:49:25.000+0000
Updated2019-11-19T15:52:46.000+0000

Description

Trying to use the Android Camera2 API CameraManager fails with this error message: Message: Uncaught TypeError: Object android.hardware.camera2.CameraManager@436cda3 has no method 'getCameraIdList' *Code:*
var Activity = require('android.app.Activity');
var Context = require("android.content.Context");
var activity = new Activity(Titanium.App.Android.getTopActivity());
var CameraManager = require("android.hardware.camera2.CameraManager");

var cameraManager = activity.getSystemService(CameraManager.class);
console.log("CameraManager: " + cameraManager);

if (cameraManager !== null) {
    var cameraIdList = cameraManager.getCameraIdList();
    console.log("CameraIDs: " + JSON.stringify(cameraIdList));
}

var cameraManager = activity.getSystemService(Context.CAMERA_SERVICE);
console.log("CameraManager: " + cameraManager);

if (cameraManager !== null) {
    var cameraIdList = cameraManager.getCameraIdList();
    console.log("CameraIDs: " + JSON.stringify(cameraIdList));
}
Android 6.0.1 Titanium 5.4.0

Comments

  1. Hans Knöchel 2016-08-20

    Moving to TIMOB. Does it work to supply the class as a String (e.g. "CameraManager" instead of CameraManager.class)? That's at least how it's done on iOS. Otherwise it's a use-case we didn't cover, yet.
  2. Michael Gangolf 2016-08-21

    I'll the string version. The fingerprint android example https://github.com/appcelerator/hyperloop-examples/blob/master/app/controllers/android/touchid.js uses the .class syntax so I've adopted that
  3. Hans Knöchel 2016-09-24

    [~michael] I think the following is the correct call:
       activity.getSystemService(Context.CAMERA_SERVICE);
       
    but it might not be called because the previous call returns something non-null that is still not able to handle getCameraIdList. So can you try to just call the second option? I'm just wondering why this specific class would not work, but others do. Thanks!
  4. Michael Gangolf 2016-09-24

    Just using this:
       var cameraManager = activity.getSystemService(Context.CAMERA_SERVICE);
       console.log("CameraManager: " + cameraManager);
       
       if (cameraManager !== null) {
           var cameraIdList = cameraManager.getCameraIdList();
           console.log("CameraIDs: " + JSON.stringify(cameraIdList));
       }
       
    will still show: {noformat} [INFO] CameraManager: android.hardware.camera2.CameraManager@2f69c118 [ERROR] TiExceptionHandler: (main) [1341,1341] ----- Titanium Javascript Runtime Error ----- [ERROR] TiExceptionHandler: (main) [0,1341] - In alloy/controllers/index.js:44,42 [ERROR] TiExceptionHandler: (main) [0,1341] - Message: Uncaught TypeError: Object android.hardware.camera2.CameraManager@2f69c118 has no method 'getCameraIdList' [ERROR] TiExceptionHandler: (main) [1,1342] - Source: var cameraIdList = cameraManager.getCameraIdList(); [ERROR] V8Exception: Exception occurred at alloy/controllers/index.js:44: Uncaught TypeError: Object android.hardware.camera2.CameraManager@2f69c118 has no method 'getCameraIdList' {noformat} A side note: I was using hyperloop 1.2.0 before and just found out, that it skipped the update to 1.2.7 everytime. When I removed the old 1.2.0 folder and run appc new again it successfully downloaded 1.2.7. But the error above is still with the latest version!
  5. Michael Gangolf 2017-05-10

    Still the same with Hyperloop 2.1.0
  6. Ygor Lemos 2019-10-31

    Hi @Michael, did you have success using Hyperloop with Camera2 API? We are looking for going this way since we need better compression on newer Android models (that capture 4k by default).
  7. Michael Gangolf 2019-10-31

    [~ygbr] no, not yet. Same error with Hyperloop 4.0.4. It might work fine creating a normal module. For me it was just a test so I didn't bother

JSON Source