Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. private PendingIntent pendingIntent;
  2.  
  3. @Override
  4. public void onCreate(Bundle savedInstanceState)
  5. {
  6.  
  7. super.onCreate(savedInstanceState);
  8. setContentView(R.layout.activity_main);
  9. Calendar calendar = Calendar.getInstance();
  10. calendar.set(Calendar.HOUR_OF_DAY, 18);
  11. calendar.set(Calendar.MINUTE, 40);
  12. calendar.set(Calendar.SECOND, 0);
  13. Intent myIntent = new Intent(MainActivity.this, MyReceiver.class);
  14. pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, myIntent,0);
  15.  
  16. AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
  17. alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent);
  18.  
  19. } //end onCreate
  20.  
  21. public static NotificationManager mManager;
  22.  
  23. @SuppressWarnings("static-access")
  24. public static void generateNotification(Context context){
  25.  
  26. mManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
  27. Intent intent1 = new Intent(context,MainActivity.class);
  28. Notification notification = new Notification(R.drawable.ic_launcher,"This is a test message!", System.currentTimeMillis());
  29. intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP| Intent.FLAG_ACTIVITY_CLEAR_TOP);
  30. PendingIntent pendingNotificationIntent = PendingIntent.getActivity(context,0, intent1,PendingIntent.FLAG_UPDATE_CURRENT);
  31. notification.flags |= Notification.FLAG_AUTO_CANCEL;
  32. notification.setLatestEventInfo(context, "AlarmManagerDemo", "This is a test message!", pendingNotificationIntent);
  33. mManager.notify(0, notification);
  34. }
  35.  
  36. @Override
  37. public IBinder onBind(Intent arg0)
  38. {
  39. // TODO Auto-generated method stub
  40. return null;
  41. }
  42.  
  43. @Override
  44. public void onCreate()
  45. {
  46. // TODO Auto-generated method stub
  47. super.onCreate();
  48. }
  49.  
  50. @Override
  51. public void onStart(Intent intent, int startId)
  52. {
  53. super.onStart(intent, startId);
  54. }
  55.  
  56. @Override
  57. public void onDestroy()
  58. {
  59. // TODO Auto-generated method stub
  60. super.onDestroy();
  61. }
  62.  
  63. @Override
  64. public void onCreate(Bundle savedInstanceState)
  65. {
  66. super.onCreate(savedInstanceState);
  67. setContentView(R.layout.activity_main);
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement