java - Android daily notification shows up multiple times at the wrong time -


i trying android notification show @ noon every day. notification seems show once whenever device started, sporadically afterwards.

here service:

public class myservice extends service { public static final string tag = "locationloggerservicemanager"; @override public void oncreate() {     // todo auto-generated method stub     super.oncreate();     log.v(tag, "on oncreate"); }   @override public int onstartcommand(intent intent, int flags, int startid) {     pendingintent contentintent = pendingintent.getactivity(this, 0, new intent(this, loginactivity.class), 0);      notificationcompat.builder mbuilder =             new notificationcompat.builder(this)             .setsmallicon(r.drawable.ic_launcher)             .setcontenttitle("app name")             .setcontenttext("notification")             .setcontentintent(contentintent)             .setdefaults(notification.default_sound)             .setautocancel(true);     notificationmanager mnotificationmanager =         (notificationmanager) this.getsystemservice(context.notification_service);     mnotificationmanager.notify("main", 1, mbuilder.build());      return super.onstartcommand(intent, flags, startid); }  @override public ibinder onbind(intent intent) {     // todo auto-generated method stub     return null; } } 

and receiver:

   public class mybroadcastreceiver extends broadcastreceiver {  public static final string tag = "locationloggerservicemanager"; @override public void onreceive(context context, intent intent) {     log.d(tag, "broadcast received");     handlemessage(context, intent); }   private void handlemessage(context context, intent intent) {     pendingintent contentintent = pendingintent.getservice(context, 0, new intent(context, myservice.class), 0);      alarmmanager alarmmanager = (alarmmanager) context.getsystemservice(context.alarm_service);     alarmmanager.cancel(contentintent);     calendar calendar = calendar.getinstance();     calendar.set(calendar.hour_of_day, 12);     calendar.set(calendar.minute, 00);     calendar.set(calendar.second, 00);     alarmmanager.setrepeating(alarmmanager.rtc_wakeup, calendar.gettimeinmillis(), 24*60*60*1000 , contentintent); } } 

any pointers appreciated. thank you.

i attempted set own notification / alarm class. way found manage extend android calendar.

if try way see link start:

http://developer.android.com/guide/topics/providers/calendar-provider.html

i have example of approach @ work, can provide code later if need it!


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -