List of usage examples for android.app Notification setLatestEventInfo
@Deprecated public void setLatestEventInfo(Context context, CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent)
From source file:net.geniecode.ttr.ScheduleReceiver.java
@SuppressWarnings("deprecation") @SuppressLint("NewApi") private void setNotification(Context context) { ScrollingText = context.getString(R.string.schedule_postponed_scroll); NotificationText = context.getString(R.string.schedule_postponed_notify); // Trigger a notification that, when clicked, will activate airplane mode mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, ActivateFlightMode.class), PendingIntent.FLAG_CANCEL_CURRENT); Notification notification; if (android.os.Build.VERSION.SDK_INT >= 11) { Notification.Builder builder = new Notification.Builder(context); builder.setContentIntent(contentIntent).setSmallIcon(R.drawable.ic_launcher).setTicker(ScrollingText) .setWhen(System.currentTimeMillis()).setAutoCancel(true).setOnlyAlertOnce(true) .setDefaults(Notification.DEFAULT_LIGHTS).setContentTitle(context.getText(R.string.app_name)) .setContentText(NotificationText); if (android.os.Build.VERSION.SDK_INT >= 16) { notification = builder.build(); } else {/*w ww. j av a2 s. co m*/ notification = builder.getNotification(); } } else { notification = new Notification(R.drawable.ic_launcher, ScrollingText, System.currentTimeMillis()); notification.setLatestEventInfo(context, context.getText(R.string.app_name), NotificationText, contentIntent); notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_LIGHTS; } mNotificationManager.notify(NOTIFICATION_ID, notification); }
From source file:org.crossconnect.bible.activity.main.ResourceFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); resourceService = ((MainActivity) getActivity()).getResourceService(); // Prepare the loader. Either re-connect with an existing one, // or start a new one. Bundle bundle = new Bundle(); bundle.putParcelable("BibleText", Utils.loadBibleText(getActivity().getSharedPreferences("APP SETTINGS", Context.MODE_PRIVATE))); getLoaderManager().initLoader(0, bundle, this); // Create an empty adapter we will use to display the loaded data. mAdapter = new ResourceListAdapter(getActivity()); setListAdapter(mAdapter);/*ww w . j a v a 2 s . c om*/ dm = ((DownloadManager) getActivity().getSystemService("download")); BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0); Query query = new Query(); query.setFilterById(enqueue); Cursor c = dm.query(query); if (c.moveToFirst()) { int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS); if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) { String uriString = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); } } String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getActivity() .getSystemService(ns); int icon = R.drawable.icon_book_rss; CharSequence tickerText = "Resource Download Complete"; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); CharSequence contentTitle = "Download Complete"; CharSequence contentText = "Click to view downloaded resources"; Intent notificationIntent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //uncomment when better // Intent notificationIntent = new Intent(getActivity(), MusicActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(getActivity(), 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); notification.flags |= Notification.FLAG_AUTO_CANCEL; int HELLO_ID = 1; mNotificationManager.notify(HELLO_ID, notification); } } }; getActivity().registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); }
From source file:com.hhunj.hhudata.ForegroundService.java
protected void showNotification(CharSequence from, CharSequence message) { // look up the notification manager service NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // The PendingIntent to launch our activity if the user selects this // notification //,/*from ww w.j a v a2 s. c om*/ PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, IncomingMessageView.class), 0); // The ticker text, this uses a formatted string so our message could be // localized String tickerText = getString(R.string.imcoming_message_ticker_text, message); // construct the Notification object. Notification notif = new Notification(R.drawable.stat_sample, tickerText, System.currentTimeMillis()); // Set the info for the views that show in the notification panel. notif.setLatestEventInfo(this, from, message, contentIntent); // // Date dt = new Date(); if (IsDuringWorkHours(dt)) { notif.defaults |= (Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE); } else { notif.defaults |= (Notification.DEFAULT_VIBRATE); } // after a 100ms delay, vibrate for 250ms, pause for 100 ms and // then vibrate for 500ms.// notif.vibrate = new long[] { 100, 250, 100, 500 }; nm.notify(R.string.imcoming_message_ticker_text, notif); }
From source file:com.CPTeam.VselCalc.AutoUpdateApk.java
protected void raise_notification() { String ns = Context.NOTIFICATION_SERVICE; NotificationManager nm = (NotificationManager) context.getSystemService(ns); String update_file = preferences.getString(UPDATE_FILE, ""); if (update_file.length() > 0) { // raise notification Notification notification = new Notification(appIcon, appName + " update", System.currentTimeMillis()); notification.flags |= NOTIFICATION_FLAGS; CharSequence contentTitle = appName + " update available"; CharSequence contentText = "Select to install"; Intent notificationIntent = new Intent(Intent.ACTION_VIEW); notificationIntent.setDataAndType( Uri.parse("file://" + context.getFilesDir().getAbsolutePath() + "/" + update_file), ANDROID_PACKAGE);/*w w w . j a va2 s .c o m*/ PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); nm.notify(NOTIFICATION_ID, notification); } else { nm.cancel(NOTIFICATION_ID); } }
From source file:com.snappy.GCMIntentService.java
@SuppressWarnings("deprecation") public void triggerNotification(Context context, String message, String fromName, Bundle pushExtras, String messageData) {// www . j av a2s .c o m if (fromName != null) { final NotificationManager notificationManager = (NotificationManager) getSystemService( NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.icon_notification, message, System.currentTimeMillis()); notification.number = mNotificationCounter + 1; mNotificationCounter = mNotificationCounter + 1; Intent intent = new Intent(this, SplashScreenActivity.class); intent.replaceExtras(pushExtras); intent.putExtra(Const.PUSH_INTENT, true); intent.setAction(Long.toString(System.currentTimeMillis())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_TASK_ON_HOME); PendingIntent pendingIntent = PendingIntent.getActivity(this, notification.number, intent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(this, context.getString(R.string.app_name), messageData, pendingIntent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_VIBRATE; notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_LIGHTS; String notificationId = Double.toString(Math.random()); notificationManager.notify(notificationId, 0, notification); } Log.i(LOG_TAG, message); Log.i(LOG_TAG, fromName); }
From source file:org.mozilla.gecko.updater.UpdateService.java
private void showDownloadFailure() { Notification notification = new Notification(R.drawable.ic_status_logo, null, System.currentTimeMillis()); Intent notificationIntent = new Intent(UpdateServiceHelper.ACTION_CHECK_FOR_UPDATE); notificationIntent.setClass(this, UpdateService.class); PendingIntent contentIntent = PendingIntent.getService(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(this, getResources().getString(R.string.updater_downloading_title_failed), getResources().getString(R.string.updater_downloading_retry), contentIntent); mNotificationManager.notify(NOTIFICATION_ID, notification); }
From source file:jp.co.conit.sss.sp.ex1.billing.BillingService.java
/** * ????/*from w w w.j a v a2s. co m*/ */ private void notificationRestore() { Context context = getApplicationContext(); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notification = new Notification(); Intent intent = new Intent(); PendingIntent pendingintent = PendingIntent.getActivity(context, 0, intent, 0); notification.icon = R.drawable.ic_status; notification.tickerText = context.getString(R.string.notification_restore); notification.flags = Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(context, context.getString(R.string.notification_restore), context.getString(R.string.notification_urge_download), pendingintent); notificationManager.notify(1, notification); }
From source file:uk.org.openseizuredetector.SdServer.java
/** * Show a notification while this service is running. *///from w w w .ja va 2s . com private void showNotification() { Log.v(TAG, "showNotification()"); CharSequence text = "OpenSeizureDetector Server Running"; Notification notification = new Notification(R.drawable.star_of_life_24x24, text, System.currentTimeMillis()); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); notification.setLatestEventInfo(this, "OpenSeizureDetector Server", text, contentIntent); notification.flags |= Notification.FLAG_NO_CLEAR; mNM = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNM.notify(NOTIFICATION_ID, notification); }
From source file:org.unchiujar.umbra2.services.LocationService.java
private Notification createNotification() { String contentTitle = getString(R.string.app_name); String running = getString(R.string.running); CharSequence tickerText = contentTitle + " " + running; // instantiate notification Notification notification = new NotificationCompat.Builder(this).setTicker(tickerText) .setWhen(System.currentTimeMillis()).setSmallIcon(R.drawable.icon).build(); notification.flags |= Notification.FLAG_NO_CLEAR; notification.flags |= Notification.FLAG_ONGOING_EVENT; // Define the Notification's expanded message and Intent: CharSequence contentText = contentTitle + " " + running; Intent notificationIntent = new Intent(this, FogOfExplore.class); // notificationIntent.setAction("android.intent.action.VIEW"); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent); return notification; }
From source file:ru.otdelit.astrid.opencrx.sync.OpencrxSyncProvider.java
@Override protected int updateNotification(Context context, Notification notification) { String notificationTitle = context.getString(R.string.opencrx_notification_title); Intent intent = new Intent(context, OpencrxPreferences.class); PendingIntent notificationIntent = PendingIntent.getActivity(context, 0, intent, 0); notification.setLatestEventInfo(context, notificationTitle, context.getString(R.string.SyP_progress), notificationIntent);//w w w . ja v a 2 s . co m return OpencrxUtilities.NOTIFICATION_SYNC; }