android - Notification not showing up at specific time using AlarmManager and BroadCast receiver -


this call broad cast receiver class

private void createalarmnotification() {      // todo auto-generated method stub         intent myintent = new intent(getapplication() , alarmset.class);             alarmmanager alarmmanager = (alarmmanager)getsystemservice(alarm_service);        pendingintent pendingintent = pendingintent.getbroadcast(getapplication(), 0, myintent, 0);        calendar calendar1 = calendar.getinstance();         calendar calendar = calendar.getinstance();         calendar.set(2015, 3, 20, 23, 55, 00);        alarm a= new alarm();        a.setalarm(mainactivity.this, calendar.gettimeinmillis(), 60*1000);   } 

this broadcast receviver class

public class alarm extends broadcastreceiver {  private final long gmt6 = alarmmanager.interval_hour * 6; private final long day = alarmmanager.interval_day;  private activitymanager activitymanager; private context context;   @override public void onreceive(context context, intent intent) {      this.context = context;     powermanager pm = (powermanager) context             .getsystemservice(context.power_service);     powermanager.wakelock wl = pm.newwakelock(             powermanager.partial_wake_lock, "");     wl.acquire();      shownotification();      wl.release(); }   public void setalarm(context context, long userhour, long userminute) {     this.context = context;     alarmmanager = (alarmmanager) context             .getsystemservice(context.alarm_service);     intent = new intent(context, alarm.class);     pendingintent pi = pendingintent.getbroadcast(context, 0, i, 0);     am.setexact(alarmmanager.rtc_wakeup, userhour, pi);  }    public void shownotification() {      uri sounduri = ringtonemanager             .getdefaulturi(ringtonemanager.type_notification);     intent intent = new intent(context, mainactivity.class);     pendingintent pintent = pendingintent             .getactivity(context, 0, intent, 0);      notification mnotification = new notification.builder(context)             .setcontenttitle("")             .setcontenttext("")             .setsmallicon(r.drawable.ic_launcher).setcontentintent(pintent)             .setsound(sounduri)             .addaction(r.drawable.ic_launcher, "view", pintent)             .addaction(0, "remind", pintent).build();      notificationmanager notificationmanager = (notificationmanager) context             .getsystemservice(context.notification_service);      mnotification.flags |= notification.flag_auto_cancel;      notificationmanager.notify(0, mnotification); }   }  } 

this manifest code

<receiver android:name="com.example.notification.alarm"     android:enabled="true"     android:exported="true" ></receiver> 

but broadcast receiver class dont show kind of notification. helpful proper suggestion solving problem.

in call

calendar.set(2015, 3, 20, 23, 55, 00);

you setting calendar's month april, not march, that's why not triggered. if want set alarm 60 seconds later, may write this:

    calendar calendar = calendar.getinstance();     a.setalarm(mainactivity.this, calendar.gettimeinmillis(), 60*1000); 

Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -