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:
final static int RQS_1 = 1;
public void setAlarm1(long interval){
/* info.setText("\n\n***\n"
+ "Alarm1 is set@ " + targetCal.getTime() + "\n"
+ "***\n");*/
Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(),RQS_1, intent, 0);
AlarmManager alarmManager1 = ((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
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Alarm received!", Toast.LENGTH_LONG).show();
}
Manifest.xml
<receiver
android:name="yourpackagename.AlarmReceiver"
android:enabled="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED"
android:process=":remote" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Permissions:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<action android: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 manager
AlarmManager alarmMgr0 = (AlarmManager) mContext
.getSystemService(Context.ALARM_SERVICE);
// Create pending intent & register it to your alarm notifier
// class
Intent intent0 = new Intent("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 work
Calendar 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"