Android Question issues with PhoneEvents

Darren Llewellyn

Member
Licensed User
Longtime User
I'm Having Issues when I try and create a PhoneEvents object all I get is an Error, I'm using v2.71 can anyone tell me where I'm going wrong with the code
I'm new to B4A so any help would be appreciated
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim PhneEvnts As phoneevents
 
End Sub
 
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
 
    Dim lblBatLvl As Label
End Sub
 
Sub Activity_Create(FirstTime As Boolean)
    'PhneEvnts.Initialize("")
   
End Sub
 
Sub Activity_Resume
 
End Sub
 
Sub Activity_Pause (UserClosed As Boolean)
 
End Sub
 
 
Sub PhneEvnts_BatteryChanged (Level As Int, Scale As Int, Plugged As Boolean, Intent As Intent)
    lblBatLvl.Text  = Level
End Sub

thanks in advance
 

bsnqt

Active Member
Licensed User
Longtime User
I think you should post also the error, people ask about the solution but being very often forgetting to describe their own issue... :) What error did you get?
 
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
First of all, I think you should create the label in designer and load the layout (for example "Layout1") when the Activity is created. You got error most likely because of this (view has not yet been declared). Secondly, you should initialize the PhoneEvents, giving it a special event name, in the attached demo I gave it a name "PhoneEvents".

Attached is a working demo, please refer to this. I would suggest you read the B4A Beginner Guide and Code Snippet document.
 

Attachments

  • DemoBatt.zip
    6.8 KB · Views: 370
Last edited:
Upvote 0

Darren Llewellyn

Member
Licensed User
Longtime User
I figured out my issue like an idiot I forgot to load the phone libary in hence my problem just sort out the changeing colour and I will be set
 
Upvote 0
Top