My Alarmmanager Not Getting Called
I try every code which I got from Stackoverflow or from anywhere, but not getting success in AlarmManager, my BroadcastReceiver not even getting called. Here is my code: //My A
Solution 1:
Try the code below:
finalstaticintRQS_1=1;
publicvoidsetAlarm1(long interval){
/* info.setText("\n\n***\n"
+ "Alarm1 is set@ " + targetCal.getTime() + "\n"
+ "***\n");*/Intentintent=newIntent(getBaseContext(), AlarmReceiver.class);
PendingIntentpendingIntent= PendingIntent.getBroadcast(getBaseContext(),RQS_1, intent, 0);
AlarmManageralarmManager1= ((ApplicationConstant)ListOfAds.this.getApplication()).getmanager();
alarmManager1 = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
//alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(), pendingIntent);
alarmManager1.setRepeating(AlarmManager.RTC_WAKEUP,interval, 60000, pendingIntent);
System.out.println("Alarm fired ListofAds:"+System.currentTimeMillis());
}
The AlarmReceiver.java
publicclassAlarmReceiverextendsBroadcastReceiver {
@OverridepublicvoidonReceive(Context context, Intent intent) {
Toast.makeText(context, "Alarm received!", Toast.LENGTH_LONG).show();
}
Manifest.xml
<receiverandroid:name="yourpackagename.AlarmReceiver"android:enabled="true"android:permission="android.permission.RECEIVE_BOOT_COMPLETED"android:process=":remote" ><intent-filter><actionandroid:name="android.intent.action.BOOT_COMPLETED" /></intent-filter></receiver>Permissions:
<uses-permissionandroid:name="android.permission.RECEIVE_BOOT_COMPLETED" /><actionandroid:name="android.intent.action.QUICKBOOT_POWERON" />Try the above code.I am sure that the Alarm Manager will get called.
Solution 2:
Finally i got What i want, with the help of @kgandroid & @rainash Here i post my Solve code now. which is working fine for me & Showing Notifications. And i also able to set here Multiple AlarmManager with my required time.
// Create alarm managerAlarmManager alarmMgr0 = (AlarmManager) mContext
.getSystemService(Context.ALARM_SERVICE);
// Create pending intent & register it to your alarm notifier// classIntent intent0 = newIntent("alarm");
intent0.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent0.putExtra("req_code", v); // pI);PendingIntent pendingIntent0 = PendingIntent
.getBroadcast(mContext, v, intent0,
PendingIntent.FLAG_UPDATE_CURRENT);
// set timer you want alarm to workCalendar timeOff9 = Calendar.getInstance();
timeOff9.setTimeInMillis(System.currentTimeMillis());
timeOff9.set(scheduleDao1.getYear(),
(scheduleDao1.getMonth()) - 1, //Months start from '0'
scheduleDao1.getDay(),
(scheduleDao1.getFromTimeHr()) - 1,//I want those notification before 1hr
scheduleDao1.getFromTimeMin(), 0);
// long dateWeGet = Long.valueOf(dateString);// set that timer as a RTC Wakeup to alarm manager object
alarmMgr0.set(AlarmManager.RTC_WAKEUP,
timeOff9.getTimeInMillis(), pendingIntent0);
contents.put(ALARM_REQUEST_CODE, v);
Post a Comment for "My Alarmmanager Not Getting Called"