Refine search
NotificationManager notificationManager = (NotificationManager) getSystemService(Service.NOTIFICATION_SERVICE); Notification notification = new Notification(/* your notification */); PendingIntent pendingIntent = /* your intent */; notification.setLatestEventInfo(this, /* your content */, pendingIntent); notificationManager.notify(/* id */, notification);
Notification ntf = new Notification(); ntf.setLatestEventInfo(this, COLOR_SEARCH_RECURSE_TIP, "Utest", null); LinearLayout group = new LinearLayout(this); ViewGroup event = (ViewGroup) ntf.contentView.apply(this, group);
/** * Issues a notification to inform the user that server has sent a message. */ private void generateNotification(String text) { int icon = R.drawable.notifiaction_icon; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, text, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, MainActivity.class); // set intent so it does not start a new activity //notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, MY_ID, notificationIntent, 0); notification.setLatestEventInfo(context, title, text, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; //PendingIntent.FLAG_ONE_SHOT notificationManager.notify(MY_ID, notification); }
int icon = R.drawable.notification_icon; // icon from resources CharSequence tickerText = "Hello"; // ticker-text long when = System.currentTimeMillis(); // notification time Context context = getApplicationContext(); // application Context CharSequence contentTitle = "My notification"; // expanded message title CharSequence contentText = "Hello World!"; // expanded message text Intent notificationIntent = new Intent(this, MyClass.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); // the next two lines initialize the Notification, using the configurations above Notification notification = new Notification(icon, tickerText, when); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); notification.defaults |= Notification.DEFAULT_SOUND; mNotificationManager.notify(1234, notification);
int icon = R.drawable.ic_launcher; CharSequence tickerText = "Reminder Created"; long when = System.currentTimeMillis(); Context context = getApplicationContext(); CharSequence contentTitle = mTitle.getText().toString(); CharSequence contentText = mContent.getText().toString(); Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); final Notification notification = new Notification(icon, tickerText, when); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); String ns = Context.NOTIFICATION_SERVICE; final NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, SnapClientActivity.class); notification.setLatestEventInfo(context, title, message, intent); notification.vibrate = new long[] { 500, 500 }; notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Notification.FLAG_SHOW_LIGHTS; notificationManager.notify(0, notification);
// this code brings the application from background to foreground // when the Notification icon is clicked on. // create new notification int icon = R.drawable.ic_notify; Notification notification = new Notification(icon, "Ticker Text", System.currentTimeMillis()); // Create new Intent pointing to activity you want it to come back to Intent notificationIntent = new Intent(this, MainApp.class); // Add new intent to a pending intent PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); // add that pendingIntent to the new notification notification.setLatestEventInfo(getApplicationContext(), "Title", "Text", contentIntent); // send the intent to the NotificationManager ((NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE)).notify(UPLOADER_ID, notification);
int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager nm=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); Intent intent=new Intent(context,MainActivity.class); PendingIntent pending=PendingIntent.getActivity(context, 0, intent, 0); Notification notification; if (Build.VERSION.SDK_INT < 11) { notification = new Notification(icon, "Title", when); notification.setLatestEventInfo( context, "Title", "Text", pending); } else { notification = new Notification.Builder(context) .setContentTitle("Title") .setContentText( "Text").setSmallIcon(R.drawable.ic_launcher) .setContentIntent(pending).setWhen(when).setAutoCancel(true) .build(); } notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_SOUND; nm.notify(0, notification);
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); int icon = R.drawable.youricon; CharSequence tickerText = "Sticky notification"; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); Context context = getApplicationContext(); CharSequence contentTitle = "Sticky notification"; CharSequence contentText = "...click here and it wont go away..."; Intent notificationIntent = new Intent(this, mainmenu.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); notification.flags |= Notification.FLAG_ONGOING_EVENT; notificationManager.notify(NOTIFICATION_EX, notification);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notification = new Notification(/* your notification */); PendingIntent pendingIntent = /* your intent */; notification.setLatestEventInfo(this, /* your content */, pendingIntent); notificationManager.notify(/* id */, notification);
int icon = R.drawable.alerte; CharSequence tickerText = getString(R.string.lieuproche); long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); Intent intent = new Intent(getApplicationContext(), ActivityToLaunch.class); notification.setLatestEventInfo( MainActivity.this, "title", "action", PendingIntent.getActivity( this.getBaseContext(), 0, intent, PendingIntent.FLAG_CANCEL_CURRENT)); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_LIGHTS; notificationManager.notify(0, notification);
NotificationManager nm = (NotificationManager) getSystemService(context.NOTIFICATION_SERVICE); Notification notification = new Notification(); notification.flag = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; Intent nIntent = new Intent(); nIntent = getPreviousIntent(); PendingIntent pi = PendingIntent.getActivity(this, 0, nIntent, 0); notification.setLatestEventInfo(getContext(), "some Title", "some text", pi); nm.notify(0,notification);
int icon = R.drawable.animationfile; long when = System.currentTimeMillis(); notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, "Your location is tracing", when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, Home.class); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, "Rohit", intent); //notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.flags |= Notification.FLAG_NO_CLEAR; notification.defaults = Notification.DEFAULT_ALL; notificationManager.notify(NOTIFICATION, notification);
public static void showNotification(Context context) { CharSequence title = "title"; CharSequence message = "text"; NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(<image>, title, System.currentTimeMillis()); notification.flags = Notification.FLAG_ONGOING_EVENT; Intent notificationIntent = new Intent(context, Provider.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, pendingIntent); notificationManager.notify(<notification id>, notification); }
String ns = Context.NOTIFICATION_SERVICE; NotificationManager notificationManager = (NotificationManager) getSystemService(ns); int icon = R.drawable.update; CharSequence tickerText = "assignments"; long when = System.currentTimeMillis(); Notification assignmentNotification = new Notification(icon, tickerText, when); assignmentNotification.defaults |= Notification.DEFAULT_SOUND; long[] vibrate = {0,100,200,300}; assignmentNotification.vibrate = vibrate; Context context = getApplicationContext(); CharSequence contentTitle = "check assignments"; CharSequence contentText = "chek ur app for assignments "; Intent notificationIntent = new Intent(context, ViewAssignmentnotificationActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,0); assignmentNotification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); ** final int id = 2;
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); int icon = R.drawable.notification_icon; CharSequence notiText = "Your notification from the service"; long meow = System.currentTimeMillis(); Notification notification = new Notification(icon, notiText, meow); Context context = getApplicationContext(); CharSequence contentTitle = "Your notification"; CharSequence contentText = "Some data has arrived!"; Intent notificationIntent = new Intent(this, YourActivityThatYouWantToLaunch.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); int SERVER_DATA_RECEIVED = 1; notificationManager.notify(SERVER_DATA_RECEIVED, notification);
// This is the 'title' of the notification CharSequence title = "Alarm!!"; // This is the icon to use on the notification int icon = R.drawable.ic_dialog_alert; // This is the scrolling text of the notification CharSequence text = "Your notification time is upon us."; // What time to show on the notification long time = System.currentTimeMillis(); Notification notification = new Notification(icon, text, time); // The PendingIntent to launch our activity if the user selects this notification PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, SecondActivity.class), 0); // Set the info for the views that show in the notification panel. notification.setLatestEventInfo(this, title, text, contentIntent); // Clear the notification when it is pressed notification.flags |= Notification.FLAG_AUTO_CANCEL; // Send the notification to the system. mNM.notify(NOTIFICATION, notification);
public static void addToNotificationBar(Context mContext,String ticker, String title, String message) { long when = System.currentTimeMillis(); int icon = R.drawable.ic_launcher; NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, new Intent(), 0); Notification notification = new Notification(icon, ticker, when); notification.setLatestEventInfo(mContext, title, message, contentIntent); notification.flags = Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
public class StatusNotificationIntent { public static Notification buildNotification( Context context, CharSequence tag, CharSequence contentTitle, CharSequence contentText) { int icon = R.drawable.notification; long when = System.currentTimeMillis(); Notification noti = new Notification(icon, contentTitle, when); noti.flags |= flag; PackageManager pm = context.getPackageManager(); Intent notificationIntent = pm.getLaunchIntentForPackage(context.getPackageName()); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); notificationIntent.putExtra("notificationTag", tag); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); noti.setLatestEventInfo(context, contentTitle, contentText, contentIntent); return noti; } }