List of usage examples for android.app NotificationManager notify
public void notify(int id, Notification notification)
From source file:org.mythdroid.util.UpdateService.java
private void checkMDD(String addr) { if (MDDVer == null) return;/*from ww w . j a va 2 s .co m*/ Version currentVer; try { currentVer = new Version(MDDManager.getVersion(addr), null); } catch (NumberFormatException e) { ErrUtil.logErr(e); return; } catch (IOException e) { ErrUtil.logErr(e); return; } if (currentVer.compareTo(MDDVer) >= 0) { LogUtil.debug("MDD on " + addr + " is already the latest version" //$NON-NLS-1$ //$NON-NLS-2$ ); return; } LogUtil.debug("MDD ver " + MDDVer.toString() + " is available (current ver on " + //$NON-NLS-1$ //$NON-NLS-2$ addr + " is " + currentVer.toString() + ")" //$NON-NLS-1$ //$NON-NLS-2$ ); if (MDVer != null && MDVer.compareTo(MDDVer) != 0) { LogUtil.warn("Version mismatch:" + " MythDroid is " + MDVer.toString() + //$NON-NLS-1$ //$NON-NLS-2$ ", MDD on " + addr + " is " + MDDVer.toString() //$NON-NLS-1$ //$NON-NLS-2$ ); } final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final Notification notification = new Notification(R.drawable.logo, Messages.getString("UpdateService.0") + "MDD" + //$NON-NLS-1$ //$NON-NLS-2$ Messages.getString("UpdateService.1"), //$NON-NLS-1$ System.currentTimeMillis()); notification.flags = Notification.FLAG_AUTO_CANCEL; final Intent intent = new Intent(MDDACTION); intent.putExtra(ADDR, addr); intent.putExtra(VER, MDDVer.toString()); intent.putExtra(URL, MDDVer.url.toString()); notification.setLatestEventInfo(getApplicationContext(), "MDD" + Messages.getString("UpdateService.2"), //$NON-NLS-1$ //$NON-NLS-2$ MDDVer.toString() + Messages.getString("UpdateService.1") + //$NON-NLS-1$ Messages.getString("UpdateService.3"), //$NON-NLS-1$ PendingIntent.getBroadcast(this, 0, intent, 0)); nm.notify(CHECKMDD, notification); }
From source file:com.bubblegum.traceratops.app.service.LoggerService.java
private void showPersistentNotification() { NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); PendingIntent pendingIntent = PendingIntent.getActivity(this, R.id.traceratops_notification_pending_intent, new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); // PendingIntent stopPendingIntent = PendingIntent.getBroadcast(this, R.id.traceratops_notification_stop_pending_intent, new Intent(ACTION_STOP), PendingIntent.FLAG_UPDATE_CURRENT); Notification notification = new NotificationCompat.Builder(this).setOngoing(true) // .addAction(new NotificationCompat.Action(R.drawable.ic_notif_stop, getString(R.string.stop), stopPendingIntent)) .setColor(ContextCompat.getColor(this, R.color.colorPrimary)) .setCategory(NotificationCompat.CATEGORY_STATUS).setPriority(NotificationCompat.PRIORITY_MIN) .setContentTitle(getString(R.string.persistent_notification_title)) .setContentText(getString(R.string.persistent_notification_text)).setContentIntent(pendingIntent) .setSmallIcon(R.drawable.ic_notif_default).build(); nm.notify(R.id.traceratops_running_id, notification); }
From source file:no.nordicsemi.android.nrftoolbox.dfu.DfuService.java
/** * Creates or updates the notification in the Notification Manager. Sends broadcast with given progress or error state to the activity. * /*from www . j a v a 2 s. c om*/ * @param progress * the current progress state or an error number, can be one of {@link #PROGRESS_CONNECTING}, {@link #PROGRESS_STARTING}, {@link #PROGRESS_VALIDATING}, {@link #PROGRESS_DISCONNECTING}, * {@link #PROGRESS_COMPLETED} or {@link #ERROR_FILE_CLOSED}, {@link #ERROR_FILE_INVALID} , etc */ private void updateProgressNotification(final int progress) { final String deviceAddress = mDeviceAddress; final String deviceName = mDeviceName != null ? mDeviceName : getString(R.string.dfu_unknown_name); final Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.stat_dfu); final Notification.Builder builder = new Notification.Builder(this) .setSmallIcon(android.R.drawable.stat_sys_upload).setOnlyAlertOnce(true).setLargeIcon(largeIcon); switch (progress) { case PROGRESS_CONNECTING: builder.setOngoing(true).setContentTitle(getString(R.string.dfu_status_connecting)) .setContentText(getString(R.string.dfu_status_connecting_msg, deviceName)) .setProgress(100, 0, true); break; case PROGRESS_STARTING: builder.setOngoing(true).setContentTitle(getString(R.string.dfu_status_starting)) .setContentText(getString(R.string.dfu_status_starting_msg, deviceName)) .setProgress(100, 0, true); break; case PROGRESS_VALIDATING: builder.setOngoing(true).setContentTitle(getString(R.string.dfu_status_validating)) .setContentText(getString(R.string.dfu_status_validating_msg, deviceName)) .setProgress(100, 0, true); break; case PROGRESS_DISCONNECTING: builder.setOngoing(true).setContentTitle(getString(R.string.dfu_status_disconnecting)) .setContentText(getString(R.string.dfu_status_disconnecting_msg, deviceName)) .setProgress(100, 0, true); break; case PROGRESS_COMPLETED: builder.setOngoing(false).setContentTitle(getString(R.string.dfu_status_completed)) .setContentText(getString(R.string.dfu_status_completed_msg)).setAutoCancel(true); break; case PROGRESS_ABORTED: builder.setOngoing(false).setContentTitle(getString(R.string.dfu_status_abored)) .setContentText(getString(R.string.dfu_status_aborted_msg)).setAutoCancel(true); break; default: if (progress >= ERROR_MASK) { // progress is an error number builder.setOngoing(false).setContentTitle(getString(R.string.dfu_status_error)) .setContentText(getString(R.string.dfu_status_error_msg)).setAutoCancel(true); } else { // progress is in percents builder.setOngoing(true).setContentTitle(getString(R.string.dfu_status_uploading)) .setContentText(getString(R.string.dfu_status_uploading_msg, deviceName)) .setProgress(100, progress, false); } } // send progress or error broadcast if (progress < ERROR_MASK) sendProgressBroadcast(progress); else sendErrorBroadcast(progress); // We cannot set two activities at once (using PendingIntent.getActivities(...)) because we have to start the BluetoothLeService first. Service is created in DeviceListActivity. // When creating activities the parent Activity is not created, it's just inserted to the history stack. final Intent intent = new Intent(this, NotificationActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(DfuActivity.EXTRA_DEVICE_ADDRESS, deviceAddress); intent.putExtra(DfuActivity.EXTRA_DEVICE_NAME, deviceName); intent.putExtra(DfuActivity.EXTRA_PROGRESS, progress); // this may contains ERROR_CONNECTION_MASK bit! if (mLogSession != null) intent.putExtra(DfuActivity.EXTRA_LOG_URI, mLogSession.getSessionUri()); final PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); final NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(NOTIFICATION_ID, builder.build()); }
From source file:com.androidquery.simplefeed.activity.PostActivity.java
private void notify(String ticker, String title, String message, Intent intent) { String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); int icon = R.drawable.launcher; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, ticker, when); Context context = getApplicationContext(); CharSequence contentText = message; int id = getNotifyId(); PendingIntent contentIntent = PendingIntent.getActivity(this, id, intent, 0); notification.setLatestEventInfo(context, title, contentText, contentIntent); mNotificationManager.cancelAll();/*from w ww . j a v a 2s . c o m*/ AQUtility.debug("notify id", id); mNotificationManager.notify(id, notification); }
From source file:com.sublimis.urgentcallfilter.Magic.java
@SuppressWarnings("deprecation") private void notification() { if (MyPreference.isNotifications()) { if (mContext != null) { NotificationManager notificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager != null) { Notification notification = new Notification(R.drawable.icon, null, System.currentTimeMillis()); Intent notificationIntent = new Intent(mContext, ActivityMain.class); if (notification != null && notificationIntent != null) { notificationIntent.setFlags(notificationIntent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(mContext, mContext.getResources().getString(R.string.notification_title), mContext.getResources().getString(R.string.notification_text), pendingIntent); notificationManager.notify(0, notification); }//from w w w . j a v a2 s . c om } } } }
From source file:com.dafeng.upgradeapp.util.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) { setChanged();//from w w w.j a va2 s. co m notifyObservers(AUTOUPDATE_HAVE_UPDATE); // 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); 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.rossier.shclechelles.service.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./*w w w. j a v a 2s . c om*/ */ private void sendNotification(String from, String message) { Gson gson = new GsonBuilder().create(); String messageUTF8 = ""; try { messageUTF8 = new String(message.getBytes(), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } Log.i("MyGCMListenerService", message); Log.i("MyGCMListenerService", messageUTF8); if (messageUTF8 == "") return; MatchNotification match = gson.fromJson(messageUTF8, MatchNotification.class); Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); int icon = R.drawable.ic_launcher_shc; long when = System.currentTimeMillis(); // Notification notification = new Notification(icon, "Nouveaux rsultats", when); Notification notification = new Notification.Builder(this.getBaseContext()) .setContentText("Nouveaux rsultats").setSmallIcon(icon).setWhen(when).build(); NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.match_notif_layout); contentView.setTextViewText(R.id.notif_team_home, match.getTeam_home()); contentView.setTextViewText(R.id.notif_team_away, match.getTeam_away()); contentView.setTextViewText(R.id.notif_result_home, match.getResult_home() + ""); contentView.setTextViewText(R.id.notif_result_away, match.getResult_away() + ""); contentView.setTextViewText(R.id.notif_ligue, match.getLigue()); contentView.setImageViewResource(R.id.notif_team_loc_logo, Utils.getLogo(match.getTeam_home())); contentView.setImageViewResource(R.id.notif_team_away_logo, Utils.getLogo(match.getTeam_away())); notification.contentView = contentView; Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.contentIntent = contentIntent; //notification.flags |= Notification.FLAG_ONGOING_EVENT; //Do not clear the notification notification.defaults |= Notification.DEFAULT_LIGHTS; // LED notification.defaults |= Notification.DEFAULT_VIBRATE; //Vibration notification.defaults |= Notification.DEFAULT_SOUND; // Sound //get topics name String[] topic = from.split("/"); mNotificationManager.notify(topic[2].hashCode(), notification); }
From source file:com.projecttango.experiments.basictango_button.MainActivity.java
public void togglestate(View view) { isOn = ((ToggleButton) view).isChecked(); // Gets an instance of the NotificationManager service NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); //Intent for Stop button on Notification Intent intent = new Intent(this, MainActivity.class); intent.putExtra("isOn", "false"); PendingIntent aIntent = PendingIntent.getActivity(this, 0, intent, 0); //Intent for Restart button on Notification Intent intent2 = new Intent(this, RestartActivity.class); intent.putExtra("isOn", "true"); PendingIntent bIntent = PendingIntent.getActivity(this, 0, intent2, 0); //NOTIFICATION SETUP NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.appicon) .setContentTitle("UTC Tango").setContentText("Collecting Data!").setOngoing(true).setPriority(2) .setAutoCancel(true).setDeleteIntent(aIntent).addAction(R.drawable.none, "Stop Session", aIntent) .addAction(R.drawable.none, "Restart", bIntent); int mNotificationId = 8001; //Notification ID if (isOn) {//from w ww .java 2s . co m //create UUID for session; uuid = UUID.randomUUID(); //Starting Toast Toast.makeText(getApplicationContext(), "Collecting Data...", Toast.LENGTH_SHORT).show(); // Builds the notification and issues it. mNotifyMgr.notify(mNotificationId, mBuilder.build()); } else { //action if button is false isOn = false; mNotifyMgr.cancelAll(); //kill notification //Stopping Toast Toast.makeText(getApplicationContext(), "Stopped collecting data", Toast.LENGTH_SHORT).show(); } }
From source file:com.airbop.library.simple.AirBopGCMIntentService.java
private static void generateImageNotification(Context context, String title, String message, String url, String image_url, String large_icon) { // The bitmap to download Bitmap message_bitmap = null;/*from w w w. j a v a 2 s . c o m*/ // Should we download the image? if ((image_url != null) && (!image_url.equals(""))) { message_bitmap = AirBopImageDownloader.downloadBitmap(image_url, context); } // If we didn't get the image, we're out of here if (message_bitmap == null) { generateNotification(context, title, message, url, large_icon); return; } AirBopManifestSettings airBop_settings = CommonUtilities.loadDataFromManifest(context); int icon = airBop_settings.mNotificationIcon; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); //if ((title == null) || (title.equals(""))) { if (title == null) { title = airBop_settings.mDefaultNotificationTitle; } Intent notificationIntent = null; if ((url == null) || (url.equals(""))) { //just bring up the app if (context != null) { ClassLoader class_loader = context.getClassLoader(); if (class_loader != null) { try { if (airBop_settings.mDefaultNotificationClass != null) { notificationIntent = new Intent(context, Class.forName(airBop_settings.mDefaultNotificationClass)); } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } else { //Launch the URL notificationIntent = new Intent(Intent.ACTION_VIEW); notificationIntent.setData(Uri.parse(url)); notificationIntent.addCategory(Intent.CATEGORY_BROWSABLE); } PendingIntent intent = null; // set intent so it does not start a new activity if (notificationIntent != null) { notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); } Builder notificationBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(message).setLargeIcon(decodeImage(large_icon)).setWhen(when) .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(message_bitmap)); if (intent != null) { notificationBuilder.setContentIntent(intent); } if (icon != 0) { notificationBuilder.setSmallIcon(icon); } Notification notification = notificationBuilder.build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:de.wikilab.android.friendica01.FileUploadService.java
private void showSuccessMsg(Context ctx) { NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); //Instantiate the Notification: int icon = R.drawable.arrow_up; CharSequence tickerText = "Upload succeeded!"; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); notification.flags |= Notification.FLAG_AUTO_CANCEL; /*/* ww w. j ava2 s . co m*/ //TODO!!! //Define the Notification's expanded message and Intent: Context context = getApplicationContext(); CharSequence contentTitle = "Upload successful, click to show details!"; CharSequence contentText = targetFilename; Intent notificationIntent = new Intent(this, FilePreview.class); Bundle b = new Bundle(); b.putInt("cid", clipId); notificationIntent.putExtras(b); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); */ //Define the Notification's expanded message and Intent: Context context = getApplicationContext(); PendingIntent nullIntent = PendingIntent.getActivity(context, 0, new Intent(), 0); notification.setLatestEventInfo(context, tickerText, "Click to dismiss", nullIntent); //Pass the Notification to the NotificationManager: mNotificationManager.notify(UPLOAD_SUCCESS_ID, notification); //Toast.makeText(ctx, "Upload failed, please retry:\n" + txt, Toast.LENGTH_LONG).show(); }