List of usage examples for android.app Notification setLatestEventInfo
@Deprecated public void setLatestEventInfo(Context context, CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent)
From source file:com.automated.taxinow.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from w w w.j a v a 2 s .c o m*/ private void generateNotification(Context context, String message) { // System.out.println("this is message " + message); // System.out.println("NOTIFICATION RECEIVED!!!!!!!!!!!!!!" + message); int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, MainDrawerActivity.class); notificationIntent.putExtra("fromNotification", "notification"); // 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, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; System.out.println("notification====>" + message); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; // notification.defaults |= Notification.DEFAULT_LIGHTS; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.ledARGB = 0x00000000; notification.ledOnMS = 0; notification.ledOffMS = 0; notificationManager.notify(0, notification); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = pm.newWakeLock( PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "WakeLock"); wakeLock.acquire(); wakeLock.release(); }
From source file:ca.mcgill.hs.serv.LogFileUploaderService.java
@Override public synchronized void onStart(final Intent intent, final int startId) { // Update the file list updateFileList();//ww w . ja v a 2 s. c o m // If there are no files, return. if (fileList.size() == 0 && !started) { makeToast(getResources().getString(R.string.uploader_no_new_files), Toast.LENGTH_SHORT); return; } // If it was already started, return. Else, continue. if (started) { return; } // At this point we consider the service to be started. started = true; registerReceiver(wifiOnlyPrefChanged, new IntentFilter(WIFI_ONLY_CHANGED_INTENT)); registerReceiver(autoPrefChanged, new IntentFilter(AUTO_UPLOAD_CHANGED_INTENT)); wifiMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifiInfo = wifiMgr.getConnectionInfo(); // Register completion receiver registerReceiver(completionReceiver, new IntentFilter(UPLOAD_COMPLETE_INTENT)); // Connect to a network setUpConnection(); notificationMgr = (NotificationManager) getSystemService(NOTIFICATION_STRING); notificationMgr.cancel(NOTIFICATION_ID); final int icon = R.drawable.notification_icon; final String tickerText = getResources().getString(R.string.notification_ticker); final String contentTitle = getResources().getString(R.string.notification_upload_title); final String contentText = getResources().getString(R.string.notification_upload_text); final Notification n = new Notification(icon, tickerText, System.currentTimeMillis()); final Intent i = new Intent(this, HSService.class); n.setLatestEventInfo(this, contentTitle, contentText, PendingIntent.getActivity(this.getBaseContext(), 0, i, PendingIntent.FLAG_CANCEL_CURRENT)); notificationMgr.notify(NOTIFICATION_ID, n); filesUploaded = 0; uploadFiles(); }
From source file:pj.rozkladWKD.C2DMReceiver.java
public void showNotification(String ticker, String contentTitle, String contentText, PendingIntent intent, int number) { String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); int icon = R.drawable.ic_launcher_wkd; CharSequence tickerText = ticker; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); Context context = getApplicationContext(); notification.number = Prefs.getNotificationMessageNextNumber(context); notification.flags |= Notification.FLAG_AUTO_CANCEL; SharedPreferences prefs = Prefs.get(context); if (prefs.getBoolean(Prefs.NOTIFICATION_SOUND, true)) notification.defaults |= Notification.DEFAULT_SOUND; if (prefs.getBoolean(Prefs.NOTIFICATION_VIBRATION, true)) notification.defaults |= Notification.DEFAULT_VIBRATE; notification.defaults |= Notification.DEFAULT_LIGHTS; notification.setLatestEventInfo(context, contentTitle, contentText, intent); mNotificationManager.notify(NOTIFICATION_ID, notification); }
From source file:io.clh.lrt.androidservice.TraceListenerService.java
private void setNotification(String msg, boolean ongoing) { NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); int icon = R.drawable.ic_launcher; CharSequence notiText = msg;//ww w .j a v a2 s . com long meow = System.currentTimeMillis(); Notification notification = new Notification(icon, notiText, meow); Context context = getApplicationContext(); CharSequence contentTitle = "LRT notification"; CharSequence contentText = msg; Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); int SERVER_DATA_RECEIVED = 1; if (ongoing) { notification.flags |= Notification.FLAG_ONGOING_EVENT; notification.flags |= Notification.FLAG_SHOW_LIGHTS; startForeground(1337, notification); } else { notificationManager.notify(SERVER_DATA_RECEIVED, notification); } }
From source file:com.nanostuffs.yurdriver.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from ww w . j av a 2s . com*/ private void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, MapActivity.class); notificationIntent.putExtra("fromNotification", "notification"); // 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, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; System.out.println("notification====>" + message); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; // notification.defaults |= Notification.DEFAULT_LIGHTS; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.ledARGB = 0x00000000; notification.ledOnMS = 0; notification.ledOffMS = 0; notificationManager.notify(AndyConstants.NOTIFICATION_ID, notification); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = pm.newWakeLock( PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "WakeLock"); wakeLock.acquire(); wakeLock.release(); }
From source file:com.etime.ETimeActivity.java
/** * Notify the user with the message "message". Notification is set to * on-going, on-going is needed to tell android not to kill the app. * The phone with vibrate, and light up on notification. If the message * is the exact same message as the last message notified then the * notification is not set again.// w w w .j ava2 s. c o m * @param message Message to notify user with */ protected void notify(String message) { if (message.equalsIgnoreCase(lastNotificationMessage)) { return; } else { lastNotificationMessage = message; } int icon = R.drawable.icon; long when = System.currentTimeMillis(); Context context = getApplicationContext(); CharSequence contentTitle = "ETime"; Intent notificationIntent = new Intent(this, ETimeActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); notification.flags |= Notification.DEFAULT_LIGHTS; notification.flags |= Notification.FLAG_ONGOING_EVENT; notification.setLatestEventInfo(context, contentTitle, message, contentIntent); mManager.notify("ETime", APP_ID, notification); }
From source file:com.tanlet.annotation.system.SystemFragment.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) void showNotifications() { Notification notification; if (Build.VERSION.SDK_INT >= 11) { notification = new Notification.Builder(getActivity()).setSmallIcon(R.drawable.help) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)) .setContentTitle("AndroidAnnotations") .setContentText("https://github.com/excilys/androidannotations/wiki/AvailableAnnotations") .build();/*from w w w . j ava 2 s . c o m*/ } else { notification = new Notification(R.drawable.ic_launcher, "AndroidAnnotations", 0); PendingIntent contentIntent = PendingIntent.getActivity(getActivity(), 0, new Intent(), 0); notification.setLatestEventInfo(getActivity(), "My notification", "Hello World!", contentIntent); } notificationManager.notify(1, notification); }
From source file:uk.org.openseizuredetector.client.SdClientService.java
/** * Show a notification while this service is running. */// w ww. j a v a 2 s . co m private void showNotification() { Log.v(TAG, "showNotification()"); CharSequence text = "Alarm Client for OpenSeizureDetector Running"; Notification notification = new Notification(R.drawable.star_of_life_24x24, text, System.currentTimeMillis()); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, ClientActivity.class), 0); notification.setLatestEventInfo(this, "Alarm Client for OpenSeizureDetector", text, contentIntent); notification.flags |= Notification.FLAG_NO_CLEAR; mNM = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNM.notify(NOTIFICATION_ID, notification); }
From source file:vn.easycare.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from w w w . j a v a 2 s . c o m*/ private void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = 0;//System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, NotificationReceivingActivity.class); // set intent so it does not start a new activity // notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent intent = PendingIntent.getActivity(context, (int) when, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, title, message, intent); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; notification.flags |= Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL; notificationManager.notify((int) when, notification); }
From source file:org.chirpradio.mobile.PlaybackService.java
private void setNotification(String title, String message) { String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); CharSequence tickerText = message; long when = System.currentTimeMillis(); int icon = R.drawable.icon; Notification notification = new Notification(icon, tickerText, when); notification.flags = Notification.FLAG_ONGOING_EVENT; Context context = getApplicationContext(); CharSequence contentTitle = title; CharSequence contentText = message; Intent notificationIntent = new Intent(this, Playing.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); mNotificationManager.notify(CHIRP_ID, notification); }