Android Question CameraEX : java NoSuchMethodException: getSupportedFlashModes []

aeropic

Active Member
Licensed User
Longtime User
Hi All,

I'm still working on my project to launch a camera after double press on power button while the device is pin locked.
Everything seems to work pretty fine but I get once every 4 times a weird exception like the one posted here after.
The camera screen is shown, the panel displays what the camera sees, but when I press on a button (example here the BtnFlash) I get an exception.
When outside the debugger, if I go on with the exception and I press power OFF + power ON to restart the camera, most often it works fine.

The camera activity (named second) is launched from a service (unlock) and just does this:
B4X:
Sub Activity_Resume
    SetShowWhenLocked
    WS.KeepAlive(True)
    Try
       InitializeCamera
    Catch
       Msgbox("fail", "")
    End Try
End Sub

Sub SetShowWhenLocked
  Dim r As Reflector
  r.Target = r.GetActivity
  r.Target = r.RunMethod("getWindow")
'  r.RunMethod2("addFlags", 6815872, "java.lang.int") 'combination of: FLAG_TURN_SCREEN_ON, FLAG_DISMISS_KEYGUARD, FLAG_SHOW_WHEN_LOCKED and FLAG_KEEP_SCREEN_ON.
  r.RunMethod2("addFlags", 2621440, "java.lang.int") 'combination of: FLAG_TURN_SCREEN_ON,  FLAG_SHOW_WHEN_LOCKED .

End Sub

Note that I've inserted a try catch around InitializeCamera as it happens to fail too (even is less frequently) ...

Any help would be greatly appreciated !

here is the log :
LogCat connected to: B4A-Bridge: samsung GT-I9305-353575059939011
--------- beginning of /dev/log/main
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
** Service (service1) Create **
** Service (service1) Start **
Connected to B4A-Bridge (Wifi)
** Activity (main) Pause, UserClosed = true **
Installing file.
Installing file.
PackageAdded: package:test.unlock
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (unlock) Create **
** Service (unlock) Start **
** Activity (main) Pause, UserClosed = true **
** Activity (second) Create, isFirst = true **
** Activity (second) Resume **
90
[Height=720, IsInitialized=false, Width=960
]
** Activity (second) Resume **
WakeLock already held.
cameraexclass_getsupportedflashmodes (B4A line: 193)
Return r.RunMethod("getSupportedFlashModes")
java.lang.NoSuchMethodException: getSupportedFlashModes []
at java.lang.Class.getConstructorOrMethod(Class.java:460)
at java.lang.Class.getDeclaredMethod(Class.java:685)
at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:214)
at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod(Reflection.java:802)
at test.unlock.cameraexclass._getsupportedflashmodes(cameraexclass.java:568)
at test.unlock.second._btnflash_click(second.java:431)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:158)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:154)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:64)
at android.view.View.performClick(View.java:4211)
at android.view.View$PerformClick.run(View.java:17267)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)


edit : to complete my post, a same exception occurs with any of these subs :
B4X:
Public Sub GetSupportedFlashModes As List
    r.target = parameters
    Return r.RunMethod("getSupportedFlashModes")
End Sub

Public Sub GetSupportedColorEffects As List
    r.target = parameters
    Return r.RunMethod("getSupportedColorEffects")
End Sub

Public Sub GetPictureSize As CameraSize
    r.target = parameters
    r.target = r.RunMethod("getPictureSize")
    Dim cs As CameraSize
    cs.Width = r.GetField("width")
    cs.Height = r.GetField("height")
    Return cs
End Sub

and switching to the front camera, then back camera again fixes the problem...
 
Last edited:

aeropic

Active Member
Licensed User
Longtime User
Are you sure that your code waits for the camera_ready event?
EDIT :
I think so... My code is exactly a copy of cameraex.

looking inside the cameraex code I see a "Camera1_Ready" sub. I do not really understand where I should wait for this flag as I never see the ToastMessage "cannot open camera" that should toast if it failed to open the camera ?
 
Last edited:
Upvote 0

aeropic

Active Member
Licensed User
Longtime User
trying to play around with this bug, I have added this in the initialization part of my software:
B4X:
Sub Activity_Resume
    SetShowWhenLocked
    WS.KeepAlive(True)
    Try
  
    InitializeCamera   

    camEx.Release    '<<<<<<<<<<<<<<<<
    InitializeCamera   '<<<<<<<<<<<<<<<<<<
  
    Catch
    Msgbox("fail", "")
    End Try
End Sub

It just releases the camera and then initializes it again.
This seems to work better as, now, it fails only once over 50 or so. When failing I do not get any java exception but the panel1 displays a strange pattern of colors (see uploaded file). Once in this situation, the camera behavec nominally and is able to shoot good pictures ... weird isn't it ?
 

Attachments

  • Screenshot_2013-11-03-11-39-10.png
    Screenshot_2013-11-03-11-39-10.png
    75.3 KB · Views: 448
Upvote 0
Top