List of usage examples for android.app NotificationManager notify
public void notify(int id, Notification notification)
From source file:ca.rmen.android.poetassistant.PoemAudioExport.java
private void notifyPoemAudioInProgress() { Log.v(TAG, "notifyPoemAudioInProgress"); cancelNotifications();//from w ww . ja v a 2s . co m Notification notification = new NotificationCompat.Builder(mContext).setAutoCancel(false).setOngoing(true) .setContentIntent(getMainActivityIntent()) .setContentTitle(mContext.getString(R.string.share_poem_audio_progress_notification_title)) .setContentText(mContext.getString(R.string.share_poem_audio_progress_notification_message)) .setSmallIcon(Share.getNotificationIcon()).build(); NotificationManager notificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(EXPORT_PROGRESS_NOTIFICATION_ID, notification); }
From source file:ca.rmen.android.poetassistant.PoemAudioExport.java
private void notifyPoemAudioReady() { Log.v(TAG, "notifyPoemAudioReady"); cancelNotifications();//w w w . j a v a2 s . c om PendingIntent shareIntent = getFileShareIntent(); Notification notification = new NotificationCompat.Builder(mContext).setAutoCancel(true) .setContentIntent(shareIntent) .setContentTitle(mContext.getString(R.string.share_poem_audio_ready_notification_title)) .setContentText(mContext.getString(R.string.share_poem_audio_ready_notification_message)) .setSmallIcon(Share.getNotificationIcon()) .addAction(Share.getShareIconId(), mContext.getString(R.string.share), shareIntent).build(); NotificationManager notificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(EXPORT_FINISH_NOTIFICATION_ID, notification); }
From source file:de.appplant.cordova.plugin.background.ForegroundService.java
public void updateNotification() { Notification n = makeNotification(); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(NOTIFICATION_ID, n); }
From source file:at.florian_lentsch.expirysync.NotifyChecker.java
private void createExpiryNotification(Context appContext, List<String> expiringProducts) { Resources res = appContext.getResources(); NotificationCompat.Builder builder = new NotificationCompat.Builder(appContext) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(res.getQuantityString(R.plurals.numberOfItemsToBeEaten, expiringProducts.size(), expiringProducts.size())) .setContentText(StringUtils.join(expiringProducts, System.getProperty("line.separator"))) .setSound(Settings.System.DEFAULT_NOTIFICATION_URI).setAutoCancel(true); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(appContext, ProductListActivity.class); // set stack (for the back button to work correctly): TaskStackBuilder stackBuilder = TaskStackBuilder.create(appContext); stackBuilder.addParentStack(ProductListActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(resultPendingIntent); NotificationManager notificationManager = (NotificationManager) appContext .getSystemService(Context.NOTIFICATION_SERVICE); // display the notification: notificationManager.notify(WASTE_NOTIFICATION, builder.build()); }
From source file:com.tcs.geofenceplugin.GeofenceTransitionsIntentService.java
private void sendNotification(String notificationDetails, String contenttext, String place) { Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); notificationDetails = notificationDetails.substring(0, notificationDetails.length() - 1); Notification n = new Notification.Builder(this).setContentTitle("Entered :" + place) .setContentText(contenttext).setSmallIcon(R.drawable.ic_launcher) .setContentIntent(notificationPendingIntent).setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL).build(); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(0, n); }
From source file:au.com.websitemasters.schools.lcps.push.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.//from w ww . j a va 2 s.com */ public void sendNotification(String message, Class clas) { //load not readed. +1. save em. int notReaded = ((SchoolsApplication) getApplicationContext()).loadBadgesCount(); notReaded++; ((SchoolsApplication) getApplicationContext()).saveBadgesCount(notReaded); //show it on badge. ShortcutBadger.applyCount(getApplicationContext(), notReaded); Intent intent = new Intent(this, clas); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.logo_gray).setContentTitle("Leschenault Catholic Primary School") .setContentText(message).setAutoCancel(true).setNumber(notReaded).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); //push realtime refresh of lists (ANN) Intent intentBroadcast = new Intent(BROADCAST_ACTION); sendBroadcast(intentBroadcast); }
From source file:fr.bmartel.android.tictactoe.gcm.MyGcmListenerService.java
/** * Called when message is received.// w w w.j av a2 s . c o m * * @param from SenderID of the sender. * @param data Data bundle containing message data as key/value pairs. * For Set of keys use data.keySet(). */ // [START receive_message] @Override public void onMessageReceived(String from, Bundle data) { String message = data.getString("message"); if (from.startsWith("/topics/" + GameSingleton.DEVICE_ID)) { Log.d(TAG, "Message: " + message); try { JSONObject object = new JSONObject(message); ArrayList<String> eventItem = new ArrayList<>(); eventItem.add(object.toString()); broadcastUpdateStringList(BroadcastFilters.EVENT_MESSAGE, eventItem); if (!GameSingleton.activityForeground) { if (object.has(RequestConstants.DEVICE_MESSAGE_TOPIC) && object.has(RequestConstants.DEVICE_MESSAGE_CHALLENGER_ID) && object.has(RequestConstants.DEVICE_MESSAGE_CHALLENGER_NAME)) { GameMessageTopic topic = GameMessageTopic .getTopic(object.getInt(RequestConstants.DEVICE_MESSAGE_TOPIC)); ChallengeMessage challengeMessage = new ChallengeMessage(topic, object.getString(RequestConstants.DEVICE_MESSAGE_CHALLENGER_ID), object.getString(RequestConstants.DEVICE_MESSAGE_CHALLENGER_NAME)); Log.i(TAG, "challenged by " + challengeMessage.getChallengerName() + " : " + challengeMessage.getChallengerId()); Intent intent2 = new Intent(this, DeviceListActivity.class); intent2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent2, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Fight!") .setContentText("challenged by " + challengeMessage.getChallengerName()) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(new Random().nextInt(9999), notificationBuilder.build()); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); boolean isScreenOn = pm.isScreenOn(); if (isScreenOn == false) { PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "MyLock"); wl.acquire(10000); PowerManager.WakeLock wl_cpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyCpuLock"); wl_cpu.acquire(10000); } GameSingleton.pendingChallengeMessage = challengeMessage; GameSingleton.pendingChallenge = true; } } } catch (JSONException e) { e.printStackTrace(); } } }
From source file:com.anysoftkeyboard.ChewbaccaUncaughtExceptionHandler.java
public void uncaughtException(Thread thread, Throwable ex) { Log.e(TAG, "Caught an unhandled exception!!!", ex); boolean ignore = false; // https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/15 //https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/433 String stackTrace = Log.getStackTrace(ex); if (ex instanceof NullPointerException) { if (stackTrace.contains( "android.inputmethodservice.IInputMethodSessionWrapper.executeMessage(IInputMethodSessionWrapper.java") || stackTrace.contains(/* w w w.j a v a 2 s .c o m*/ "android.inputmethodservice.IInputMethodWrapper.executeMessage(IInputMethodWrapper.java")) { Log.w(TAG, "An OS bug has been adverted. Move along, there is nothing to see here."); ignore = true; } } else if (ex instanceof java.util.concurrent.TimeoutException) { if (stackTrace.contains(".finalize")) { Log.w(TAG, "An OS bug has been adverted. Move along, there is nothing to see here."); ignore = true; } } if (!ignore && AnyApplication.getConfig().useChewbaccaNotifications()) { String appName = DeveloperUtils.getAppDetails(mApp); final CharSequence utcTimeDate = DateFormat.format("kk:mm:ss dd.MM.yyyy", new Date()); final String newline = DeveloperUtils.NEW_LINE; String logText = "Hi. It seems that we have crashed.... Here are some details:" + newline + "****** UTC Time: " + utcTimeDate + newline + "****** Application name: " + appName + newline + "******************************" + newline + "****** Exception type: " + ex.getClass().getName() + newline + "****** Exception message: " + ex.getMessage() + newline + "****** Trace trace:" + newline + stackTrace + newline; logText += "******************************" + newline + "****** Device information:" + newline + DeveloperUtils.getSysInfo(mApp); if (ex instanceof OutOfMemoryError || (ex.getCause() != null && ex.getCause() instanceof OutOfMemoryError)) { logText += "******************************\n" + "****** Memory:" + newline + getMemory(); } logText += "******************************" + newline + "****** Log-Cat:" + newline + Log.getAllLogLines(); String crashType = ex.getClass().getSimpleName() + ": " + ex.getMessage(); Intent notificationIntent = new Intent(mApp, SendBugReportUiActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); final Parcelable reportDetailsExtra = new SendBugReportUiActivity.BugReportDetails(ex, logText); notificationIntent.putExtra(SendBugReportUiActivity.EXTRA_KEY_BugReportDetails, reportDetailsExtra); PendingIntent contentIntent = PendingIntent.getActivity(mApp, 0, notificationIntent, 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(mApp); builder.setSmallIcon( Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ? R.drawable.notification_error_icon : R.drawable.ic_notification_error) .setColor(ContextCompat.getColor(mApp, R.color.notification_background_error)) .setTicker(mApp.getText(R.string.ime_crashed_ticker)) .setContentTitle(mApp.getText(R.string.ime_name)) .setContentText(mApp.getText(R.string.ime_crashed_sub_text)) .setSubText(BuildConfig.TESTING_BUILD ? crashType : null/*not showing the type of crash in RELEASE mode*/) .setWhen(System.currentTimeMillis()).setContentIntent(contentIntent).setAutoCancel(true) .setOnlyAlertOnce(true).setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE); // notifying NotificationManager notificationManager = (NotificationManager) mApp .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(R.id.notification_icon_app_error, builder.build()); } // and sending to the OS if (!ignore && mOsDefaultHandler != null) { Log.i(TAG, "Sending the exception to OS exception handler..."); mOsDefaultHandler.uncaughtException(thread, ex); } Thread.yield(); //halting the process. No need to continue now. I'm a dead duck. System.exit(0); }
From source file:com.conceptberria.wattion.background.MakeNotification.java
/** * Notifica la notificacin generada//from ww w. j a v a 2 s. com * @param mBuilder */ private void notify(final NotificationCompat.Builder mBuilder) { PendingIntent resultPendingIntent; if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) { resultPendingIntent = getPendingIntent(); } else { resultPendingIntent = getPendingIntentWithStackBuilder(); } mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(NOTIF_ALERT, mBuilder.build()); }
From source file:au.com.websitemasters.schools.thornlie.push.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.//from ww w . j ava 2s . com */ private void sendNotification(String message, Class clas) { //load not readed. +1. save em. int notReaded = ((SchoolsApplication) getApplicationContext()).loadBadgesCount(); notReaded = notReaded + 1; ((SchoolsApplication) getApplicationContext()).saveBadgesCount(notReaded); //show it on badge. ShortcutBadger.applyCount(getApplicationContext(), notReaded); Intent intent = new Intent(this, clas); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.logopush).setContentTitle("Sacred Heart School Thornlie") .setContentText(message).setAutoCancel(true).setNumber(notReaded).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); //push realtime refresh of lists (ANN) Intent intentBroadcast = new Intent(BROADCAST_ACTION); sendBroadcast(intentBroadcast); }