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:
AddReceiverText(PowerConnectedReceiver,
    <intent-filter>
        <action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
    </intent-filter>)

and a service module named PowerConnectedReceiver,

B4X:
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
 

DonManfred

Expert
Licensed User
Longtime User
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Would the Battery_Changed event of the PhoneEvents library not suffice?

B4X:
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

dune3000

Member
Licensed User
Longtime User
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
Top