#Region Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private NativeMe As JavaObject
Dim b As Beeper
Dim Notif As Int
End Sub
Sub Service_Create
'This is the program entry point.
'This is a good place to load resources that are not specific to a single activity.
NativeMe.InitializeContext
b.Initialize(700,700)
End Sub
Sub Service_Start (StartingIntent As Intent)
StartServiceAt("", DateTime.Now + 8000,False)
Notif = 0
Dim status As Int = NativeMe.RunMethod("getBatteryStatus", Null)
Dim status2 As Int = NativeMe.RunMethod("getBatteryStatus2", Null)
Dim status3 As Int = NativeMe.RunMethod("isScreenLocked", Null)
Dim status4 As Int = NativeMe.RunMethod("isScreenOn", Null)
'Log("Charging status= "& status)
'Log("Charge Level =" & status2)
'Log("Screen Locked =" & status3)
'Log("Screen on =" & status4)
If status =5 Then
Notif =1
End If
If status =2 And status2 = 1 Then
Notif = 1
End If
If Notif =1 And status4 = 1 And status3 = 0 Then
ToastMessageShow("Device is fully charged. Please unplug.", True)
b.Beep
End If
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub Service_Destroy
End Sub
#if JAVA
import android.os.BatteryManager;
import android.content.Context;
import android.content.IntentFilter;
import android.content.Intent;
import android.app.KeyguardManager;
import android.os.PowerManager;
public int getBatteryStatus(){
IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = getApplicationContext().registerReceiver(null, ifilter);
int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
return status;
}
public int getBatteryStatus2(){
IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = getApplicationContext().registerReceiver(null, ifilter);
int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
int batteryPct = level / scale;
return batteryPct;
}
public int isScreenLocked(){
int myint = 0;
KeyguardManager myKM = (KeyguardManager) getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE);
boolean mybool= myKM.inKeyguardRestrictedInputMode ();
if (mybool==true) myint=1;
return myint;
}
public int isScreenOn(){
int myint = 0;
PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
boolean mybool2 = pm.isScreenOn();
if (mybool2==true) myint=1;
return myint;
}
#end if