Android Question Problems with the_PhoneEvents_BatteryChange

stu14t

Active Member
Licensed User
Longtime User
I'm having an issue with this code (Which worked until I updated my laptop):

B4X:
Sub thePhoneEvents_BatteryChanged (Level As Int, Scale As Int, Plugged As Boolean, Intent As Intent)
    If Level = 15 Then
        Msgbox2("The Battery level is down to 15% Consider recharging or replcing the battery!","Core","OK","","",LoadBitmap(File.DirAssets,"Exclamation-icon.png"))  
    End If
    If Level = 5 Then
        Msgbox2("The Battery level is down to " & Level & "% You Risk Losing Data. RECHARGE OR REPLACE THE BATTERY NOW!","Core","OK","","",LoadBitmap(File.DirAssets,"Exclamation-icon.png"))
    End If
    'Log("The battery level is: " & Level)
End Sub

This is the error dump:

B4X:
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Core.data_2014.main:_thephoneevents_batterychanged, [12, null, false, (Intent) Intent { act=android.intent.action.BATTERY_CHANGED flg=0x60000010 (has extras) }]
Error occurred on line: 955 (main)
java.lang.IllegalArgumentException: argument 2 should have type int, got null
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:305)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
    at anywheresoftware.b4a.phone.PhoneEvents$ActionHandler$1.run(PhoneEvents.java:321)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5103)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
    at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **
Timeline: Activity_idle id: android.os.BinderProxy@423605c8 time:4504569

Any thoughts on why Scale has now become Null?

Update - Only does this in Debug (Rapid) mode. Debug (Legacy) is ok
 
Last edited:

stu14t

Active Member
Licensed User
Longtime User
Hi Erel, I'm using the current version 4.0

I'll PM the project if that's ok?

Only seem's to do it in Rapid debug mode
 
Upvote 0

stu14t

Active Member
Licensed User
Longtime User
Your code also runs fine this end

In my app this code is running as a sub within the main program. I note you start a service, is this a better way to monitor the battery?
 
Upvote 0
Top