Android Question Widget + CameraExClass

jesustarre

Member
Licensed User
Longtime User
Hello, World!

I'm developed a little flashlight using CameraExClass in order to turn on/off the phone led and now it's time to implement a widget (just a button to turn on/off the led); I already add a widget service but when I declare Cam As CameraExClass under "process_Globals" I have a compiling error:

Parsing code. 0.05
Compiling code. Error
Error compiling program.
Error description: Cannot access activity object from sub Process_Globals.
Occurred on line: 12
Dim camEx2 As CameraExClass
Word: cameraexclass

I will appreciate any help

Thanks in advance
 

jesustarre

Member
Licensed User
Longtime User
You cannot declare the camera (or any activity object) in Process_Globals, you have to do it in Globals.
Thanks NJ

Doesn't work. It's possible use "Globals" in a WidgetService?

This is my WidgetService code so far

B4X:
#Region  Service Attributes
    #StartAtBoot: False
#End Region


Sub process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private frontCamera As Boolean = False
    Dim rv As RemoteViews
End Sub

Sub Globals
    Dim camEx2 As CameraExClass
End Sub

Sub Service_Create
    rv = ConfigureHomeWidget("fls_widget", "rv", 0, "FlashlightSaber")

End Sub

Sub Service_Start (StartingIntent As Intent)
    If rv.HandleWidgetEvents(StartingIntent) Then Return
  
  
End Sub

Sub rv_RequestUpdate
    rv.UpdateWidget
End Sub


Sub rv_Disabled
    StopService("")
End Sub
Sub Service_Destroy

End Sub

Sub ButtonW_Click
    Dim flashModes As List = camEx2.GetSupportedFlashModes

    If flashModes.IsInitialized = False Then
        ToastMessageShow("Flash not supported.", False)
        Return
    End If
    If camEx2.GetFlashMode="off" Then
      camEx2.SetFlashMode("torch")
    Else
      camEx2.SetFlashMode("off")
    End If
    camEx2.CommitParameters  
End Sub
 
Last edited:
Upvote 0

jesustarre

Member
Licensed User
Longtime User
Sounds interesting!

Several flashlight app on GPlay have this widget, may be they are using something like you are talking about (triggers)

Where can I find some sample about triggers app from widgets?

Thanks!
 
Upvote 0

XverhelstX

Well-Known Member
Licensed User
Longtime User
Hi

The source code for cameraex class is available on its topic.
You can remove the activityobject annotiation and compile the librar yourself (with SLC (erels tool).)

It should work as i had to use the camera in a service too and it worked.

Regards,
Tomas
 
Upvote 0

jesustarre

Member
Licensed User
Longtime User
Thanks XX!

Sound good but I think it's beyond my knowledge about B4A. Do you have any little sample? I just want turn On<>Off the Led Camera (Torch mode) from a widget
 
Upvote 0

mitobobo

Member
Licensed User
Longtime User
Hi

The source code for cameraex class is available on its topic.
You can remove the activityobject annotiation and compile the librar yourself (with SLC (erels tool).)

It should work as i had to use the camera in a service too and it worked.

Regards,
Tomas

Dear Tomas,

Would you be so kind to send me the library you compiled, please? I'd be really really grateful. Thank you so much for your precious time! :)
 
Upvote 0

mitobobo

Member
Licensed User
Longtime User
Any idea how to? Desperately need it :(

UPDATE:
I copied the source code of camera library in a camera".java file, and removed "@ActivityObject" as suggested above. Then I tried to compile it with SLC tool but I get the following error:
B4X:
Starting step: Compiling Java code.
javac 1.7.0_21
C:\Users\****\Downloads\SimpleLibraryCompiler\SimpleLibraryCompiler\FirstLibrary\src\com\example\CameraW.java:13: error: cannot find symbol
  public Camera camera;
          ^
  symbol:  class Camera
  location: class CameraW
1 error


Error.

Help please? :(
 
Last edited:
Upvote 0

mitobobo

Member
Licensed User
Longtime User
If all you want is to remove the @ActivityObject then you do not need to recompile the library. You can open the XML file and change the owner node to process. I expect it to fail without the ActivityObject however it is worth a try.

First of all, thank you so much for your answer, Erel, we all really appreciate your time and help!

I changed <owner>activity</owner> to <owner>process</owner> but I get the following error:

B4X:
Error occurred on line: 32 (cameraexclass)
java.lang.NullPointerException
    at anywheresoftware.b4a.objects.CameraW.shared(CameraW.java:70)
    at anywheresoftware.b4a.objects.CameraW.Initialize2(CameraW.java:59)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:519)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:235)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:174)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:157)
    at smartsecurity.official.pushservice.handleStart(pushservice.java:68)
    at smartsecurity.official.pushservice.onStartCommand(pushservice.java:53)
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2833)
    at android.app.ActivityThread.access$2000(ActivityThread.java:159)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1419)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5419)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
    at dalvik.system.NativeStart.main(Native Method)
(Intent) Intent { act=android.intent.action.MAIN flg=0x20000000 cmp=smartsecurity.official/.main }
no extras

Line 32 is: cam.Initialize2(Panel1, "camera", id) in CameraExClass.

Ty again :)
 
Upvote 0
Top