List of usage examples for android.app NotificationManager notify
public void notify(int id, Notification notification)
From source file:com.brq.wallet.lt.notification.GcmIntentService.java
private void showAdNotification(String type) { Intent intent;//from w ww . java 2s .co m if (LtApi.AD_TIME_OUT_NOTIFICATION_TYPE.equals(type)) { intent = PinProtectedActivity.createIntent(this, LtMainActivity.createIntent(this, LtMainActivity.TAB_TYPE.MY_ADS)); } else { // We don't know this type, so we ignore it return; } PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); String title = getResources().getString(R.string.lt_mycelium_local_trader_title); String message = getResources().getString(R.string.lt_ad_deactivating_message); NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContentTitle(title) .setContentText(message).setSmallIcon(R.mipmap.ic_launcher).setContentIntent(pIntent) .setAutoCancel(true); // Add ticker builder.setTicker(message); LocalTraderManager ltManager = MbwManager.getInstance(this).getLocalTraderManager(); // Vibrate long[] pattern = { 500, 500 }; builder.setVibrate(pattern); // Make a sound if (ltManager.getPlaySoundOnTradeNotification()) { Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (alarmSound != null) { builder.setSound(alarmSound); } } // Notify NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(0, builder.build()); }
From source file:com.brq.wallet.lt.notification.GcmIntentService.java
private void showTradeNotification(String type, long lastChange) { Intent intent;//from ww w.j a v a 2s . co m if (LtApi.TRADE_FINAL_NOTIFICATION_TYPE.equals(type)) { intent = LtMainActivity.createIntent(this, LtMainActivity.TAB_TYPE.TRADE_HISTORY); } else { intent = LtMainActivity.createIntent(this, LtMainActivity.TAB_TYPE.ACTIVE_TRADES); } Intent pinProtectedIntent = PinProtectedActivity.createIntent(this, intent); PendingIntent pIntent = PendingIntent.getActivity(this, 0, pinProtectedIntent, PendingIntent.FLAG_CANCEL_CURRENT); String title = getResources().getString(R.string.lt_mycelium_local_trader_title); String message = getResources().getString(R.string.lt_new_trading_activity_message); NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContentTitle(title) .setContentText(message).setSmallIcon(R.mipmap.ic_launcher).setContentIntent(pIntent) .setAutoCancel(true); // Add ticker builder.setTicker(message); // Tell other listeners that we have taken care of audibly notifying up // till this timestamp LocalTraderManager ltManager = MbwManager.getInstance(this).getLocalTraderManager(); ltManager.setLastNotificationSoundTimestamp(lastChange); // Vibrate long[] pattern = { 500, 500 }; builder.setVibrate(pattern); // Make a sound if (ltManager.getPlaySoundOnTradeNotification()) { Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (alarmSound != null) { builder.setSound(alarmSound); } } // Notify NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(0, builder.build()); }
From source file:com.android.madpausa.cardnotificationviewer.MainActivity.java
public void sendTestNotification(View view) { NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(this); nBuilder.setContentTitle("Test Notification!"); nBuilder.setContentText("This is just a test"); nBuilder.setSmallIcon(R.drawable.ic_notification); Notification notification = nBuilder.build(); NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Long millis = currentTimeMillis(); nManager.notify(millis.intValue(), notification); }
From source file:com.akaashvani.akaashvani.geofence.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. *//*from ww w . java 2s. co m*/ private void sendNotification(String notificationDetails) { // Create an explicit content Intent that starts the main Activity. Intent notificationIntent = new Intent(getApplicationContext(), TabActivity.class); // Construct a task stack. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Add the main Activity to the task stack as the parent. stackBuilder.addParentStack(TabActivity.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.me) // In a real app, you may want to use a library like Volley // to decode the Bitmap. .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.me)).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.hedgehog.smdb.ActionBarControlScrollViewActivity.java
private void showNotification() { Notification notification = null; Intent toLive = new Intent(this, ActionBarControlScrollViewActivity.class); PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), toLive, 0); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { notification = new Notification.Builder(this).setContentTitle("Time to Check the new Show!") .setContentInfo("").setSmallIcon(R.mipmap.ic_launcher).setContentIntent(pIntent) .setPriority(Notification.PRIORITY_MAX).setDefaults(Notification.DEFAULT_VIBRATE) .setAutoCancel(true).setOnlyAlertOnce(true) // .setTicker("Show running!") // .addAction(R.mipmap.ic_launcher, "View", pIntent) .build();//from w w w . j a v a 2 s. c o m } NotificationManager NM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notification.flags |= Notification.FLAG_AUTO_CANCEL; NM.notify(0, notification); }
From source file:cl.telematica.android.alimentame.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. *//*from w w w . jav a 2s. c o 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.mipmap.ic_launcher) // In a real app, you may want to use a library like Volley // to decode the Bitmap. .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) .setColor(Color.RED).setContentTitle(notificationDetails) .setContentText(getString(R.string.geofence_transition_notification_text)) .setVibrate(new long[] { 100, 250, 100, 500 }) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .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.balch.mocktrade.services.OrderService.java
private void sendNotification(Order order, String msg) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(this.getString(R.string.notification_order_title)) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); // TODO: Make this go somewhere cool Intent clickIntent = new Intent(this, TemplateActivity.class); PendingIntent pendingClickIntent = PendingIntent.getActivity(this, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingClickIntent); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // int id = R.id.notification_order_id; int id = (int) (order.getId() % Integer.MAX_VALUE); notificationManager.notify(id, builder.build()); }
From source file:alaindc.memenguage.RandomIntentService.java
private void sendNotification(long id_word) { String title = "Memenguage"; String description = "Do you remember?"; // Create an explicit content Intent that starts the main Activity. Intent notificationIntent = new Intent(getApplicationContext(), GuessActivity.class); notificationIntent.setAction(Constants.ACTION_GUESS_ACTIVITY); notificationIntent.putExtra(Constants.EXTRA_GUESS_IDWORD, id_word); // 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.addNextIntentWithParentStack(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.icon) // In a real app, you may want to use a library like Volley // to decode the Bitmap. .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.logo)).setColor(Color.RED) .setContentTitle(title).setContentText(description).setDefaults(Notification.DEFAULT_ALL) .setContentIntent(notificationPendingIntent); try {//from ww w. j a v a2s . c o m String urisound = PreferenceManager.getDefaultSharedPreferences(this).getString("sound_notifications", ""); builder.setSound(Uri.parse(urisound)); } catch (Exception e) { Log.d("RandomIntentService", "Uri sound notification empty or wrong"); } try { Boolean vibrate = PreferenceManager.getDefaultSharedPreferences(this) .getBoolean("vibrate_notifications", false); if (vibrate) builder.setVibrate(new long[] { 1000, 1000 }); } catch (Exception e) { Log.d("RandomIntentService", "Vibrate notification wrong"); } builder.setDefaults(0); // 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(Constants.ID_NOTIFICATION_RANDOM_WORD, builder.build()); }
From source file:com.cpd.receivers.LibraryRenewAlarmBroadcastReceiver.java
public void launchNotification(Context context, String title, String message) { // Extender for Android Wear NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender() .setBackground(BitmapFactory.decodeResource(context.getResources(), R.drawable.library_wear_bg)); // Build notification NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context); notificationBuilder.setSmallIcon(R.drawable.ic_stat_name); notificationBuilder/* ww w . j a va2 s . com*/ .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)); notificationBuilder.setContentTitle(title); notificationBuilder.setContentText(message); notificationBuilder.setLights(ContextCompat.getColor(context, R.color.pureRed), 2000, 2000); notificationBuilder.setAutoCancel(true); notificationBuilder.extend(wearableExtender); //TODO: criar extra no intent pra tratar abertura da pag da biblio! Intent resultIntent = new Intent(context, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); notificationBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. int idNotify = 1; mNotificationManager.notify(idNotify, notificationBuilder.build()); }
From source file:com.example.pyrkesa.shwc.OngoingNotificationListenerService.java
@Override public void onDataChanged(DataEventBuffer dataEvents) { final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); final String ACTION_DEMAND = "ACTION_DEMAND"; String EXTRA_CMD = "EXTRA_CMD"; dataEvents.close();//from w w w . j a va2s.co m if (!mGoogleApiClient.isConnected()) { ConnectionResult connectionResult = mGoogleApiClient.blockingConnect(30, TimeUnit.SECONDS); if (!connectionResult.isSuccess()) { Log.e(TAG, "Service failed to connect to GoogleApiClient."); return; } } for (DataEvent event : events) { if (event.getType() == DataEvent.TYPE_CHANGED) { String path = event.getDataItem().getUri().getPath(); if (PATH.equals(path)) { // Get the data out of the event DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem()); //final String title = dataMapItem.getDataMap().getString(KEY_TITLE); final String room_devices = dataMapItem.getDataMap().getString(KEY_ROOM_DEVICES); final String room_name = dataMapItem.getDataMap().getString(KEY_ROOM_NAME); // Asset asset = dataMapItem.getDataMap().getAsset(KEY_BACKGROUND); try { JSONObject roomJSON = new JSONObject(room_devices); JSONArray devicesArray = roomJSON.getJSONArray("devices"); String firstPageText = "quipements :"; ArrayList<Device> devicess = new ArrayList<Device>(); for (int i = 0; i < devicesArray.length(); i++) { JSONObject d = devicesArray.getJSONObject(i); Device device = new Device(d.getString("id"), d.getString("name"), d.getInt("type"), d.getString("status")); String Newline = System.getProperty("line.separator"); firstPageText += Newline; firstPageText += device.name; devicess.add(device); } if (firstPageText.equalsIgnoreCase("quipements :")) { firstPageText = "Aucun quipement"; } Bitmap background = BitmapFactory.decodeResource(this.getResources(), R.drawable.bg_distance); NotificationCompat.WearableExtender notifExtender = new NotificationCompat.WearableExtender(); for (Device d : devicess) { try { notifExtender.addAction(d.getAction(OngoingNotificationListenerService.this)); } catch (Exception e) { Log.e("Erreur get Action :", e.getMessage()); } } NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setContentTitle("Pice : " + roomJSON.getString("name")) .setContentText(firstPageText).setSmallIcon(R.drawable.mini_logo) .extend(notifExtender.setBackground(background)).setOngoing(true); // Build the notification and show it NotificationManager notificationManager = (NotificationManager) getSystemService( NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); } catch (Throwable t) { Log.e("JSON_WEAR_SHWC", "Could not parse malformed JSON: " + room_devices + t.getMessage()); } } else { Log.d(TAG, "Unrecognized path: " + path); } } } }