Guest User

Untitled

a guest
Aug 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. Create reminder in android app
  2. pendingIntent = PendingIntent.getBroadcast(SettingsActivity.this, 1234567, new Intent(SettingsActivity.this, WeeklyReminder.class), 0);
  3. AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis());
  4. calendar.add(Calendar.SECOND, 30);
  5. long updateFreq = 30*1000;//24*60*60*1000;
  6. alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), updateFreq, pendingIntent);
  7.  
  8. public class WeeklyReminder extends BroadcastReceiver
  9. {
  10.  
  11. @Override
  12. public void onReceive(Context context, Intent intent)
  13. {
  14. // TODO Auto-generated method stub
  15. try
  16. {
  17. System.out.println("Alarm Initiated");
  18. Toast.makeText(context, "Recieved Alarm", Toast.LENGTH_SHORT).show();
  19. }
  20. catch (Exception e)
  21. {
  22. Toast.makeText(context, "There was an error somewhere, but we still received an alarm", Toast.LENGTH_SHORT).show();
  23. e.printStackTrace();
  24. }
  25. }
  26.  
  27. }
  28.  
  29. <receiver android:name="WeeklyReminder">
  30.  
  31. <receiver android:name=".WeeklyReminder">
Add Comment
Please, Sign In to add comment