Android Question Catch power connected event

dune3000

Member
Licensed User
Longtime User
Hi,
I want to catch the power connected event by add receiver to manifest.xml

B4X: Copy
AddReceiverText(PowerConnectedReceiver,
    <intent-filter>
        <action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
    </intent-filter>)

and a service module named PowerConnectedReceiver,

B4X: Copy
Sub Service_Start (StartingIntent As Intent)
    Log("Power Connected!")
    Service.StopAutomaticForeground 'Call this when the background task completes (if there is one)
End Sub

but no effect, any sugguestion?

Thanks
 
 
Upvote 0
Would the Battery_Changed event of the PhoneEvents library not suffice?

Code: Copy
Sub Process_Globals
'...
   Private pe As PhoneEvents
'...
End Sub

Sub Service_Create
'...
   pe.Initialize("pe")
'...
End Sub

Sub pe_BatteryChanged (Level As Int, Scale As Int, Plugged As Boolean, Intent As Intent)
    Log(Plugged)
End Sub
 
Upvote 0
Thank you @DonManfred, you pointed me to the right direction, now I just changed the targetSdkVersion to "25", and it works!
@OliverA, because I want to catch power connected and power disconnected events.
 
Upvote 0
Back
Top