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
 

mitobobo

Member
Licensed User
Longtime User
B4X:
Panel1.Initialize("Panel1")
before "cam.Initialize2(Panel1, "camera", id)" in CameraExClass, is that right?
 
Upvote 0

mitobobo

Member
Licensed User
Longtime User
Yes. But you may also need to add it to a parent.

Create two panels and add Panel1 to Panel2.

B4X:
Public Sub Initialize (Panel1 As Panel, FrontCamera As Boolean, TargetModule As Object, EventName As String)
    target = TargetModule
    event = EventName
    Front = FrontCamera
    Dim id As Int
    id = FindCamera(Front).id
    If id = -1 Then
        Front = Not(Front) 'try different camera
        id = FindCamera(Front).id
        If id = -1 Then
            ToastMessageShow("No camera found.", True)
            Return
        End If
    End If
Dim Panel2 As Panel
    Panel2.Initialize("")
    Panel2.AddView(Panel1, 1,1,1,1)
    cam.Initialize2(Panel1, "camera", id)
End Sub

But I get the following error:
B4X:
Error compiling program.
Error description: An Activity context is required.
This class has a process context.
Adding a global "Activity object" variable will fix this issue.
Occurred on line: 35
Panel2.Initialize("")
Word: initialize

I even tried to add "Dim Panel2 As Panel" in Sub Class_Globals but then it won't accept "Private camEx As CameraExClass" in Sub Process_Globals of the service anymore.
 
Upvote 0

mitobobo

Member
Licensed User
Longtime User
This is expected as services do not have the "correct" context. How did you initialize Panel1?

I really want to thank you once again for your help and time, Erel. To get this fixed is really important to me. Thank you. I initialized Panel1 through Panel1.Initialize("Panel1") though I get the error: "This class has a process context. Adding a global "Activity object" variable will fix this issue........". Is there another way to initialize it?
 
Upvote 0

mitobobo

Member
Licensed User
Longtime User
Not really. I'm sorry but this library was built to work with activities not services.

will work hard and try try and try. I have been working on this app for about a year and won't stop right now ;-(

Thank you very very much for your help Erel! If you'll have some news - please let us know :) jesustarre is on my same situation.
 
Upvote 0
Top