In My application i am going to use this code to use the Notification:
private void addDefaultNotification(){
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
int icon = R.drawable.icon;
CharSequence text = "Notification Text";
CharSequence contentTitle = "Notification Title";
CharSequence contentText = "Sample notification text.";
long when = System.currentTimeMillis();
Intent intent = new Intent(this, NotificationViewer.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification notification = new Notification(icon,text,when);
long[] vibrate = {0,100,200,300};
notification.vibrate = vibrate;
notification.ledARGB = Color.RED;
notification.ledOffMS = 300;
notification.ledOnMS = 300;
notification.defaults |= Notification.DEFAULT_LIGHTS;
//notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent);
notificationManager.notify(com.example.NotifivcationSample.Constants.NOTIFICATION_ID, notification);
}
rightnow i am getting the notofication. By calling that function. But i want is that it should be notify the user even if the application is not runing on at that time on device and notification should be notify on the desired time.
Is it possible ? If yes then please help me for that. Thanks.
Edited:
public class AlarmNotificationReceiver extends BroadcastReceiver{
//private Intent intent;
private NotificationManager notificationManager;
private Notification notification;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
long value1 = intent.getLongExtra("param1", 0);
String value2 = intent.getStringExtra("param2");
addTwoMonthNotification();
}
}
I have done like that but not able to create notification in that receiver class. Why ? and what should i have to do ?