Advertisement
Tashfikk

Test

Jun 23rd, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. public void setAlarm(int day,int hour,int minit){
  2.  
  3.  
  4.  
  5.  
  6. Calendar cal = Calendar.getInstance();
  7.  
  8.  
  9.  
  10. cal.set(Calendar.HOUR_OF_DAY, hour);
  11. cal.set(Calendar.MINUTE,minit );
  12. cal.set(Calendar.SECOND, 0);
  13. cal.set(Calendar.MILLISECOND, 0);
  14. cal.set(Calendar.DAY_OF_WEEK, day);
  15.  
  16.  
  17. Intent intent = new Intent(this, MyBroadcastReceiver.class);
  18. PendingIntent pendingIntent = PendingIntent.getBroadcast(
  19. this.getApplicationContext(), 234324243, intent, 0);
  20. AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
  21. alarmManager.set(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis() , pendingIntent);
  22.  
  23.  
  24. }
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. package tashfik.nsugradetracker;
  36.  
  37. import java.util.Calendar;
  38.  
  39. import android.app.Notification;
  40. import android.app.NotificationManager;
  41. import android.app.PendingIntent;
  42. import android.content.BroadcastReceiver;
  43. import android.content.Context;
  44. import android.content.Intent;
  45. import android.media.Ringtone;
  46. import android.media.RingtoneManager;
  47. import android.net.Uri;
  48. import android.os.Vibrator;
  49. import android.provider.Settings;
  50. import android.util.Log;
  51.  
  52.  
  53. /**
  54. * @author Prabu
  55. *
  56. */
  57. public class MyBroadcastReceiver extends BroadcastReceiver {
  58. @Override
  59. public void onReceive(Context context, Intent intent) {
  60.  
  61.  
  62. // Vibrate the mobile phone
  63. Vibrator vibrator = (Vibrator) context
  64. .getSystemService(Context.VIBRATOR_SERVICE);
  65. vibrator.vibrate(1000);
  66. Uri at = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  67. Ringtone r = RingtoneManager.getRingtone(context,at );
  68. r.play();
  69.  
  70. NotificationManager mNM;
  71. mNM = (NotificationManager)context.getSystemService(context.NOTIFICATION_SERVICE);
  72. // Set the icon, scrolling text and timestamp
  73. Notification notification = new Notification(R.drawable.notil, "NSUGT !",System.currentTimeMillis());
  74. // The PendingIntent to launch our activity if the user selects this notification
  75. PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, HomePage.class), 0);
  76. // Set the info for the views that show in the notification panel.
  77. notification.setLatestEventInfo(context, context.getText(R.string.notification_title), "Hi ! Get ready for NSU. You got class at . .", contentIntent);
  78. // Send the notification.
  79. // We use a layout id because it is a unique number. We use it later to cancel.
  80. mNM.notify(R.string.hello_world, notification);
  81.  
  82. }
  83.  
  84.  
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement