Android : Send notification in android

on Wednesday, September 10, 2014


I have an app, and would like to send a notification at specific time every day. this is my code:



AlarmManager am = (AlarmManager)getBaseContext().getSystemService(alarm);
Intent intent = new Intent("WAKE_UP");
PendingIntent sender = PendingIntent.getBroadcast(getBaseContext(), 0, intent, 0);

time use AlarmManager.set().

am.setRepeating(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis() , AlarmManager.INTERVAL_DAY, sender);

// Prepare intent which is triggered if the
// notification is selected
Intent intent2 = new Intent(this, NotificationReceiverActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent2, 0);

// Build notification
// Actions are just fake
Notification noti = new Builder(this)
.setContentTitle(" boghche " + "shake")
.setContentText("Shake kon :/").setSmallIcon(R.drawable.icon)
.setContentIntent(pIntent)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;

notificationManager.notify(0, noti);


But I can not send it in specific time.


0 comments:

Post a Comment