in your main activity type down the below code:
-------------------------------------------------------------------------------------------------
/*this notification will come everyday night at 8PM*/
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 20);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
Intent intent1 = new Intent(this, NotifyByBraodCast.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
this, 0, intent1,
PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) this
.getSystemService(this.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, pendingIntent);
---------------------------------------------------------------------------------------------------
make a class name : NotifyByBraodCast and type down the below code:
---------------------------------------------------------------------------------------------------
public class NotifyByBraodCast extends BroadcastReceiver {
NotificationManager nm;
@Override
public void onReceive(Context context, Intent intent) {
nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence from = "Title";
CharSequence message = "Description!";
Intent notificationIntent = new Intent(context, splash.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
Notification notification = new Notification(android.R.drawable.ic_media_play, "Let's Play!", System.currentTimeMillis());
notification.setLatestEventInfo(context, from, message, contentIntent);
notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
nm.notify(1, notification);
}
}
-------------------------------------------------------------------------------------------------
/*this notification will come everyday night at 8PM*/
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 20);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
Intent intent1 = new Intent(this, NotifyByBraodCast.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
this, 0, intent1,
PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) this
.getSystemService(this.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, pendingIntent);
---------------------------------------------------------------------------------------------------
make a class name : NotifyByBraodCast and type down the below code:
---------------------------------------------------------------------------------------------------
public class NotifyByBraodCast extends BroadcastReceiver {
NotificationManager nm;
@Override
public void onReceive(Context context, Intent intent) {
nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence from = "Title";
CharSequence message = "Description!";
Intent notificationIntent = new Intent(context, splash.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
Notification notification = new Notification(android.R.drawable.ic_media_play, "Let's Play!", System.currentTimeMillis());
notification.setLatestEventInfo(context, from, message, contentIntent);
notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
nm.notify(1, notification);
}
}
No comments:
Post a Comment