List of usage examples for android.content Context NOTIFICATION_SERVICE
String NOTIFICATION_SERVICE
To view the source code for android.content Context NOTIFICATION_SERVICE.
Click Source Link
From source file:ar.com.martinrevert.argenteam.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 om*/ private void generarNotification(Context context, String message, String urlimagen, String urlarticulo, String tipo, String fecha) { SharedPreferences preferencias = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); boolean vib = preferencias.getBoolean("vibraoff", false); boolean movieoff = preferencias.getBoolean("movieoff", false); boolean tvoff = preferencias.getBoolean("tvoff", false); String ringmovie = preferencias.getString("prefRingtonemovie", ""); String ringtv = preferencias.getString("prefRingtonetv", ""); //Todo traducir ticker String ticker = "Nuevo subttulo " + tipo + " en aRGENTeaM"; Random randomGenerator = new Random(); int randomInt = randomGenerator.nextInt(100); Bitmap bitmap = getRemoteImage(urlimagen, tipo); Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); int dash = 500; int short_gap = 200; long[] pattern = { 0, // Start immediately dash, short_gap, dash, short_gap, dash }; Intent notificationIntent; String ringtone; int ledlight; if (tipo.equalsIgnoreCase("Movie")) { ringtone = ringmovie; notificationIntent = new Intent(context, Peli.class); ledlight = preferencias.getInt("ledMovie", 0); } else { notificationIntent = new Intent(context, Tv.class); ringtone = ringtv; ledlight = preferencias.getInt("ledTV", 0); System.out.println(ledlight); } notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); notificationIntent.putExtra("passed", urlarticulo); PendingIntent pendingIntent; pendingIntent = PendingIntent.getActivity(context, randomInt, notificationIntent, 0); Notification myNotification; myNotification = new NotificationCompat.Builder(context).setPriority(1).setContentTitle(message) .setTicker(ticker).setLights(ledlight, 300, 300).setWhen(System.currentTimeMillis()) .setContentIntent(pendingIntent).setSound(Uri.parse(ringtone)).setAutoCancel(true) .setSmallIcon(R.drawable.ic_stat_ic_argenteam_gcm).build(); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { RemoteViews views; views = new RemoteViews(getPackageName(), R.layout.custom_notification); views.setImageViewBitmap(R.id.big_picture, bitmap); views.setImageViewBitmap(R.id.big_icon, BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_ic_argenteam_gcm)); views.setTextViewText(R.id.title, message); myNotification.bigContentView = views; } NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (movieoff && tipo.equalsIgnoreCase("Movie")) { if (vib) { v.vibrate(pattern, -1); } notificationManager.notify(randomInt, myNotification); } if (tvoff && tipo.equalsIgnoreCase("Serie TV")) { if (vib) { v.vibrate(pattern, -1); } notificationManager.notify(randomInt, myNotification); } }
From source file:com.pti.mates.GcmIntentService.java
private void sendNotificationChat(String msg, String senderid) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); /*Cursor caux;/*from w w w . j ava2s . co m*/ caux = getApplicationContext().getContentResolver().query(DataProvider.CONTENT_URI_PROFILE, new String[] {DataProvider.COL_ID}, DataProvider.COL_FBID + "=" + senderid, null, null); Intent intent = new Intent(this, ChatActivity.class); intent.putExtra(Common.PROFILE_ID, caux.getString(caux.getColumnIndex(DataProvider.COL_ID)));*/ PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(getApplicationContext(), MainActivity.class), 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("New chat message") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.hybris.mobile.lib.location.geofencing.service.GeofencingIntentService.java
/** * Send a notification when a geofence is triggered * * @param geofence the geofence triggered * @param notification the notification object * @param geofenceTransition the geofence transition type */// www.j a v a 2s .c o m protected void sendNotification(Geofence geofence, GeofenceObject.Notification notification, int geofenceTransition) { if (notification != null) { // Notification String notificationContentTitle = notification.getNotificationTitle(); String notificationContentText = notification.getNotificationText(); int notificationIconResId = notification.getNotificationIconResId(); Notification.Builder builder = new Notification.Builder(this); builder.setContentTitle(notificationContentTitle).setContentText(notificationContentText); if (notificationIconResId > 0) { builder.setSmallIcon(notificationIconResId); } try { // Intent on click on the notification if (StringUtils.isNotBlank(notification.getIntentClassDestination())) { Class<?> intentClassDestination = Class.forName(notification.getIntentClassDestination()); // Create an explicit content Intent that starts the Activity defined in intentClassDestination Intent notificationIntent = new Intent(this, intentClassDestination); // Geofence Id to pass to the activity in order to retrieve the object if (notification.getIntentBundle() != null) { GeofenceObject.IntentBundle intentBundle = notification.getIntentBundle(); notificationIntent.putExtra(intentBundle.getKeyName(), intentBundle.getBundle()); // Easter egg :) if (intentBundle.getBundle().getBoolean(GeofencingConstants.EXTRA_PLAY_SOUND)) { MediaPlayer mediaPlayer; if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER) { Log.d(TAG, "Playing entering geofence sound"); mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.entering_geofence); } else { Log.d(TAG, "Playing exiting geofence sound"); mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.leaving_geofence); } mediaPlayer.start(); } } PendingIntent notificationPendingIntent = PendingIntent.getActivity(this, geofence.getRequestId().hashCode(), notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(notificationPendingIntent); } } catch (ClassNotFoundException e) { Log.e(TAG, "Unable to find class " + notification.getIntentClassDestination() + "." + e.getLocalizedMessage()); } // Constructing the Notification and setting the flag to auto remove the notification when the user click on it Notification notificationView; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { notificationView = builder.build(); } else { notificationView = builder.getNotification(); } notificationView.flags = Notification.FLAG_AUTO_CANCEL; notificationView.defaults = Notification.DEFAULT_ALL; // Get an instance of the Notification manager NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Issue the notification mNotificationManager.notify(UUID.randomUUID().toString().hashCode(), notificationView); } else { Log.e(TAG, "Notification empty for Geofence " + geofence); } }
From source file:ca.mudar.snoozy.receiver.PowerConnectionReceiver.java
private void notify(Context context, boolean isConnectedPower, boolean hasVibration, boolean hasSound, int notifyCount) { final Resources res = context.getResources(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_notify).setContentTitle(res.getString(R.string.notify_content_title)) .setAutoCancel(true);/*from ww w .j a v a 2 s . co m*/ if (notifyCount == 1) { final int resContentTextSingle = (isConnectedPower ? R.string.notify_content_text_single_on : R.string.notify_content_text_single_off); mBuilder.setContentText(res.getString(resContentTextSingle)); } else { mBuilder.setNumber(notifyCount).setContentText(res.getString(R.string.notify_content_text_multi)); } if (hasVibration && hasSound) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND); } else if (hasVibration) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } else if (hasSound) { mBuilder.setDefaults(Notification.DEFAULT_SOUND); } // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(context, MainActivity.class); final Bundle extras = new Bundle(); extras.putBoolean(Const.IntentExtras.INCREMENT_NOTIFY_GROUP, true); extras.putBoolean(Const.IntentExtras.RESET_NOTIFY_NUMBER, true); resultIntent.putExtras(extras); resultIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); mBuilder.setContentIntent( PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT)); Intent receiverIntent = new Intent(context, PowerConnectionReceiver.class); receiverIntent.setAction(Const.IntentActions.NOTIFY_DELETE); PendingIntent deleteIntent = PendingIntent.getBroadcast(context, Const.RequestCodes.RESET_NOTIFY_NUMBER, receiverIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setDeleteIntent(deleteIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // NOTIFY_ID allows updates to the notification later on. mNotificationManager.notify(Const.NOTIFY_ID, mBuilder.build()); }
From source file:com.keylesspalace.tusky.util.NotificationManager.java
public static void clearNotifications(@Nullable Context context) { if (context != null) { SharedPreferences notificationPreferences = context.getSharedPreferences("Notifications", Context.MODE_PRIVATE); notificationPreferences.edit().putString("current", "[]").apply(); android.app.NotificationManager manager = (android.app.NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); //noinspection ConstantConditions manager.cancel(NotificationPullJobCreator.NOTIFY_ID); }// w ww .j av a2 s . c o m }
From source file:com.google.android.gms.location.sample.geofencing.GeofenceTransitionsIntentService.java
/** * Posts a notification in the notification bar when a transition is detected. * If the user clicks the notification, control goes to the MainActivity. *///w w w . j av a2 s . co m private void sendNotification(String notificationDetails) { // Create an explicit content Intent that starts the main Activity. Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class); // Construct a task stack. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Add the main Activity to the task stack as the parent. stackBuilder.addParentStack(MainActivity.class); // Push the content Intent onto the stack. stackBuilder.addNextIntent(notificationIntent); // Get a PendingIntent containing the entire back stack. PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Get a notification builder that's compatible with platform versions >= 4 NotificationCompat.Builder builder = new NotificationCompat.Builder(this); // Define the notification settings. builder.setSmallIcon(R.drawable.ic_launcher) // In a real app, you may want to use a library like Volley // to decode the Bitmap. .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)) .setColor(Color.RED).setContentTitle(notificationDetails) .setContentText(getString(R.string.geofence_transition_notification_text)) .setContentIntent(notificationPendingIntent); // Dismiss notification once the user touches it. builder.setAutoCancel(true); // Get an instance of the Notification manager NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Issue the notification mNotificationManager.notify(0, builder.build()); }
From source file:com.teinproductions.tein.papyrosprogress.UpdateCheckReceiver.java
private static void issueNotification(Context context, Set<String> addedMilestones, Set<String> removedMilestones, Map<String, int[]> changedProgresses) { String title = context.getString(R.string.notification_title); StringBuilder message = new StringBuilder(); // Changed progresses for (String milestoneTitle : changedProgresses.keySet()) { int oldProgress = changedProgresses.get(milestoneTitle)[0]; int newProgress = changedProgresses.get(milestoneTitle)[1]; message.append("\n").append(String.format(context.getString(R.string.notific_msg_text_format), milestoneTitle, oldProgress, newProgress)); }//ww w . j a v a2 s . c om // Added milestones for (String milestoneTitle : addedMilestones) { message.append("\n").append(context.getString(R.string.milestone_added_notification, milestoneTitle)); } // Removed milestones for (String milestoneTitle : removedMilestones) { message.append("\n").append(context.getString(R.string.milestone_removed_notification, milestoneTitle)); } // Remove first newline message.delete(0, 1); // Create PendingIntent PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); boolean sound = pref.getBoolean(Constants.NOTIFICATION_SOUND_PREF, true); boolean vibrate = pref.getBoolean(Constants.NOTIFICATION_VIBRATE_PREF, true); boolean light = pref.getBoolean(Constants.NOTIFICATION_LIGHT_PREF, true); int defaults = 0; if (sound) defaults = defaults | Notification.DEFAULT_SOUND; if (vibrate) defaults = defaults | Notification.DEFAULT_VIBRATE; if (light) defaults = defaults | Notification.DEFAULT_LIGHTS; // Build the notification NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(message).setContentIntent(pendingIntent) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)) .setSmallIcon(R.mipmap.notification_small_icon) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)) .setDefaults(defaults).setAutoCancel(true); // Issue the notification NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(PROGRESS_NOTIFICATION_ID, builder.build()); }
From source file:org.mythdroid.util.UpdateService.java
private void checkMythDroid() { if (MDVer == null) return;// w w w . j ava2s.c o m Version runningVer; try { runningVer = new Version(getPackageManager().getPackageInfo(getPackageName(), 0).versionName, null); } catch (NameNotFoundException e) { return; } if (runningVer.compareTo(MDVer) >= 0) { LogUtil.debug("Already running latest version of MythDroid"); //$NON-NLS-1$ return; } LogUtil.debug("Version " + MDVer.toString() + //$NON-NLS-1$ " is available (current version is " + runningVer.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") + "MythDroid" + //$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(MDACTION); intent.putExtra(VER, MDVer.toString()); intent.putExtra(URL, MDVer.url.toString()); notification.setLatestEventInfo(getApplicationContext(), "MythDroid" + Messages.getString("UpdateService.2"), //$NON-NLS-1$ //$NON-NLS-2$ MDVer.toString() + Messages.getString("UpdateService.1") + //$NON-NLS-1$ Messages.getString("UpdateService.3"), //$NON-NLS-1$ PendingIntent.getBroadcast(this, 0, intent, 0)); nm.notify(CHECKMD, notification); }
From source file:org.ttrssreader.utils.Utils.java
/** * Shows a notification indicating that something is running. When called with finished=true it removes the * notification.//from w w w. j a v a2s.c o m * * @param context the context * @param finished if the notification is to be removed */ private static void showRunningNotification(Context context, boolean finished, Intent intent) { if (context == null) return; NotificationManager mNotMan = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // if finished remove notification and return, else display notification if (finished) { mNotMan.cancel(ID_RUNNING); return; } int icon = R.drawable.notification_icon; CharSequence title = context.getText(R.string.Utils_DownloadRunningTitle); CharSequence ticker = context.getText(R.string.Utils_DownloadRunningTicker); Notification notification = buildNotification(context, icon, ticker, title, "", true, intent); mNotMan.notify(ID_RUNNING, notification); }