Android Question Camera2 Problem at Android 5

MarkusR

Well-Known Member
Licensed User
hello,
i will use the camera 2 but it gave me an error.
my device have 5.0.2 API 21 19. Dezember 2014
and it should work and i believe i tested it long ago and it worked.
at my tablet device with android 6.0 it works.

at os 5 the example said: Failed to open camera
B4X:
Sub OpenCamera (front As Boolean)
    rp.CheckAndRequest(rp.PERMISSION_CAMERA)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        ToastMessageShow("No permission!", True)
        Return
    End If
 
    SetState(False, False, VideoMode)
    Wait For (cam.OpenCamera(front)) Complete (TaskIndex As Int)
    If TaskIndex > 0 Then
        MyTaskIndex = TaskIndex 'hold this index. It will be required in later calls.
        Wait For(PrepareSurface) Complete (Success As Boolean)
    End If
    Log("Start success: " & Success)
    SetState(Success, False, VideoMode)
    If Success = False Then
        ToastMessageShow("Failed to open camera", True)
    End If
    Log(cam.ActiveArraySize)
End Sub
the used example:
https://www.b4x.com/android/forum/threads/camera2-still-images-and-videos.83920/#post-531669
 
Last edited:

Erel

Administrator
Staff member
Licensed User
Does CameraEx (1) work with your device?

Not all Android 5 devices properly support the relatively new Camera2 API. Check the logs and you will see a message about LEGACY support.
 

MarkusR

Well-Known Member
Licensed User
just found u updated this cameraex at 06/2018 :) my used source code was outdated.
https://www.b4x.com/android/forum/threads/class-cameraex-extends-the-camera-library-functionality.23801/#content

yes there was LEGACY in log in camera2.

this cameraex(1) example have all feature that i need.
for any reason it ends the app after first test, i believe there is an issue with flash light and camera at my drevice.
second test works. i will try using this 06/2018 version thank you erel.

i had this error message in log.
Logger verbunden mit: motorola XT1032
--------- beginning of main
0.6838819980621338, 1.0923869609832764, 2.7128748893737793
java.lang.RuntimeException: startPreview failed
at android.hardware.Camera.startPreview(Native Method)
at anywheresoftware.b4a.objects.CameraW.StartPreview(CameraW.java:177)
at anywheresoftware.b4a.samples.camera.cameraexclass._startpreview(cameraexclass.java:379)
at anywheresoftware.b4a.samples.camera.main._camera1_picturetaken(main.java:676)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:360)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1058)
at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:1013)
at anywheresoftware.b4a.samples.camera.cameraexclass._camera_picturetaken(cameraexclass.java:599)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:360)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA$1.run(BA.java:330)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5312)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
** Activity (main) Pause, UserClosed = true **
** Service (starter) Destroy (ignored)**
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
 
Top