Skip to content

Commit

Permalink
alarm
Browse files Browse the repository at this point in the history
  • Loading branch information
hussienalrubaye committed Nov 1, 2016
1 parent 0fc1974 commit 259dddd
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions AlarmManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,44 @@ public void startAlert() {
Calendar myAlarmDate = Calendar.getInstance();
myAlarmDate.setTimeInMillis(System.currentTimeMillis());
myAlarmDate.set(2012, 11, 25, 12, 00, 0);
//other way
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, Hour);
calendar.set(Calendar.MINUTE, Minute);
calendar.set(Calendar.SECOND, 0);

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

Intent intent = new Intent(this, MyBroadcastReceiver.class);
intent.putExtra("MyMessage","HERE I AM PASSING THEPERTICULAR
MESSAGE WHICH SHOULD BE SHOW ON RECEIVER OF ALARM");
PendingIntent pendingIntent = PendingIntent.getBroadcast(
this.getApplicationContext(),
234324243, intent, 0);
//start service
// PendingIntent pendingIntent = PendingIntent.getService(
this.getApplicationContext(),
0, intent, 0);
alarmManager.set(AlarmManager.RTC_WAKEUP,
myAlarmDate.getTimeInMillis(),_myPendingIntent);
/* Create Repeating Alarm Start After Each 2 Minutes
am.setRepeating(AlarmManager.ELAPSED_REALTIME,myAlarmDate.getTimeInMillis(),
2*60*60,pendingIntent);
*/
//define Repeating Alarm Start After Each 2 Minutes


AlarmManager am = (AlarmManager)context.getSystemService (Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmReceiver.class);
intent.setAction("com.quranonline.Broadcast");
intent.putExtra("MyMessage",context.getResources().getString(R.string.msg_notify));
PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY , pi);
// Create one time Alarm Start After Each 2 Minutes
alarmManager.set(AlarmManager.RTC_WAKEUP, myAlarmDate.getTimeInMillis(),_myPendingIntent);


}


/* Permission need
<uses-permission android:name="android.permission.VIBRATE" />
*/
*/

/* run with os
//permission
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
//filters
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
<action android:name="android.intent.action.QUICKBOOT_POWEROFF" />
*/

0 comments on commit 259dddd

Please sign in to comment.