If p.SdkVersion < 23 Then
StartServiceAtExact("", RestartTime, True)
Else 'https://www.b4x.com/android/forum/threads/now-android-6-servicestartatexact-not-accurate.65117/#post-414796
Dim srvAt As JavaObject
'call the function
srvAt.InitializeContext
srvAt.RunMethod("StartServiceAtExactWhileIdle", Array(RestartTime, True))
End If
#If JAVA
//import android.app.Service;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
import android.provider.Settings;
import android.provider.Settings.Secure;
public void StartServiceAtExactWhileIdle(Long time, Boolean wakeUp){
AlarmManager alMan = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this.getApplicationContext(), this.getClass());
PendingIntent penInt = PendingIntent.getService(this.getApplicationContext(), 1, intent, 134217728);
alMan.setExactAndAllowWhileIdle(wakeUp?AlarmManager.RTC_WAKEUP:AlarmManager.RTC, time, penInt);
}
#End If