Search the Community
Showing results for tags 'alarmmanager'.
Found 2 results
-
I need to open application periodically every minute. For testing I have a simple application with just this code that should open the application: function getTimeAfterInSecs(Seconds: Integer): Int64; var Calendar: JCalendar; begin Calendar := TJCalendar.JavaClass.getInstance; Calendar.add(TJCalendar.JavaClass.SECOND, Seconds); Result := Calendar.getTimeInMillis; end; procedure TForm2.Button1Click(Sender: TObject); var Intent: JIntent; PendingIntent: JPendingIntent; LFlags: Integer; begin Intent := TJIntent.Create; Intent.setClassName(TAndroidHelper.Context, StringToJString('com.embarcadero.firemonkey.FMXNativeActivity')); LFlags := TJPendingIntent.JavaClass.FLAG_UPDATE_CURRENT or TJPendingIntent.JavaClass.FLAG_IMMUTABLE; PendingIntent := TJPendingIntent.JavaClass.getActivity(TAndroidHelper.Context, 1, Intent, LFlags); TAndroidHelper.AlarmManager.&set(TJAlarmManager.JavaClass.RTC_WAKEUP, getTimeAfterInSecs(60), PendingIntent); end; procedure TForm2.Button2Click(Sender: TObject); var Intent: JIntent; PendingIntent: JPendingIntent; LFlags: Integer; AlarmManager: JAlarmManager; begin Intent := TJIntent.Create; Intent.setClassName(TAndroidHelper.Context, StringToJString('com.embarcadero.firemonkey.FMXNativeActivity')); LFlags := TJPendingIntent.JavaClass.FLAG_UPDATE_CURRENT or TJPendingIntent.JavaClass.FLAG_IMMUTABLE; PendingIntent := TJPendingIntent.JavaClass.getActivity(TAndroidHelper.Context, 0, Intent, LFlags); AlarmManager := TJAlarmManager.Wrap(TAndroidHelper.Context.getSystemService(TJContext.JavaClass.ALARM_SERVICE)); AlarmManager.setExactAndAllowWhileIdle(TJAlarmManager.JavaClass.RTC_WAKEUP, getTimeAfterInSecs(60), PendingIntent); end; Unfortunately the application does not open. What am I doing wrong?
-
Hi, I am looking for Delphi examples on waking up an application when an Android device is in sleep mode. Setting an alarm with the AlarmManager TAndroidHelper.AlarmManager.&set(TJAlarmManager.JavaClass.RTC_WAKEUP,...) fires MyAppEvent on time, it writes a message in the Memo, but the app does NOT wake up. function TfrMain.MyAppEvent(aAppEvent: TApplicationEvent; AContext: TObject): Boolean; begin result := False; case aAppEvent of TApplicationEvent.BecameActive: memo1.Lines.Add('BecameActive'); ... Only when I manually wake up the device, I see the app appear on screen. How can wake up the device when MyAppEvent notifies the event of becoming active? Even more, the app should become on the front of other running applications in the case the device is not asleep. I've searched already on the possibilities of the AlarmManager and the PowerManager, but found nothing to wake up while being asleep. Any example would be appreciated!