Advertisement
Adeeb

alarmManager

Apr 6th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1.             /*
  2.             The following is the code for setting up the alarm
  3.             */
  4.  
  5.             //use alarm manager to time new event everyday
  6.             Intent in = new Intent(application_context,ProfileChanger.class);
  7.             PendingIntent pin = PendingIntent.getBroadcast(application_context, 0, in, 0);
  8.            
  9.             Calendar cal = Calendar.getInstance();
  10.             String[] time = someEvent.getTime().split(":");
  11.             cal.set(Calendar.HOUR, Integer.parseInt(time[0]));
  12.             cal.set(Calendar.MINUTE, Integer.parseInt(time[1]));
  13.            
  14.             alarm.setRepeating(AlarmManager.ELAPSED_REALTIME,
  15.             cal.getTimeInMillis(),AlarmManager.INTERVAL_DAY, pin);
  16.  
  17.             /*
  18.             Here's my class which responds when the alarm goes off
  19.             It's in a class which extends BroadcastReciever, here's my onRecieve Method
  20.             */
  21.             public void onReceive(Context arg0, Intent arg1) {
  22.                 //This toast is never displayed
  23.                 Toast.makeText(arg0, "Hello World", Toast.LENGTH_LONG).show();
  24.                
  25.                 arg0.getSystemService(Context.AUDIO_SERVICE);
  26.                 profileChanger = new Sound(am);
  27.                
  28.                 String event_type;
  29.                 event_type = arg1.getStringExtra("event_type");
  30.                 if (event_type.equals("Lecture")){
  31.                     profileChanger.silent();
  32.                 }
  33.                 else if(event_type.equals("Tutorial")){
  34.                     profileChanger.vibrate();
  35.                 }
  36.                 else if(event_type.equals("Other")){
  37.                     profileChanger.vibrate();
  38.                 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement