List of usage examples for android.app NotificationManager notify
public void notify(int id, Notification notification)
From source file:com.upnext.blekit.actions.BLEAction.java
/** * Displays a notification//from w w w .j a v a 2 s . co m * * @param context Android Context, passed from the calling entity * @param title title for the notification * @param msg message and ticker for the notification * @param type action type that will be put as an extra into the result Intent (<code>resultIntent.putExtra("type", type);</code>) * @param notificationIconResId notification icon resource id * @param notificationId an identifier for this notification as in {@link android.app.NotificationManager#notify(int, android.app.Notification)} */ public static void displayNotification(Context context, String title, String msg, String type, int notificationIconResId, int notificationId) { L.d("."); if (BLEKit.getTargetActivityForNotifications() == null) { throw new IllegalArgumentException( "Target activity for notifications is not set. Call BLEKit.getTargetActivityForNotifications() first."); } Notification.Builder builder = new Notification.Builder(context).setContentText(msg).setTicker(msg) .setContentTitle(title).setAutoCancel(true).setSmallIcon(notificationIconResId); Intent resultIntent = new Intent(context, BLEKit.getTargetActivityForNotifications()); resultIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); resultIntent.putExtra("type", type); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(notificationId, builder.build()); }
From source file:br.com.bioscada.apps.biotracks.io.sendtogoogle.SendToGoogleUtils.java
/** * Sends a notification to request permission. * /*from www .ja v a2 s . co m*/ * @param context the context * @param accountName the account name * @param intent the intent * @param notificaitonId the notification id */ public static void sendNotification(Context context, String accountName, Intent intent, int notificaitonId) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(Intent.FLAG_FROM_BACKGROUND); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setAutoCancel(true) .setContentIntent(pendingIntent) .setContentText(context.getString(R.string.permission_request_message, accountName)) .setContentTitle(context.getString(R.string.permission_request_title)) .setSmallIcon(android.R.drawable.ic_dialog_alert) .setTicker(context.getString(R.string.permission_request_title)); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(notificaitonId, builder.build()); }
From source file:com.achep.acdisplay.ui.activities.MainActivity.java
private static void sendTestNotification(@NonNull Context context) { final int id = App.ID_NOTIFY_TEST; final Resources res = context.getResources(); PendingIntent pendingIntent = PendingIntent.getActivity(context, id, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle() .bigText(res.getString(R.string.notification_test_message_large)); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setContentTitle(res.getString(R.string.app_name)) .setContentText(res.getString(R.string.notification_test_message)).setContentIntent(pendingIntent) .setLargeIcon(BitmapFactory.decodeResource(res, R.mipmap.ic_launcher)) .setSmallIcon(R.drawable.stat_acdisplay).setAutoCancel(true).setStyle(bts) .setColor(App.ACCENT_COLOR)/* w ww . j a va2s . c o m*/ .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(id, builder.build()); }
From source file:com.bullmobi.message.ui.activities.MainActivity.java
private static void sendTestNotification(@NonNull Context context) { final int id = App.ID_NOTIFY_TEST; final Resources res = context.getResources(); PendingIntent pendingIntent = PendingIntent.getActivity(context, id, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle() .bigText(res.getString(R.string.notification_test_message_large)); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setContentTitle(res.getString(R.string.app_name)) .setContentText(res.getString(R.string.notification_test_message)).setContentIntent(pendingIntent) .setLargeIcon(BitmapFactory.decodeResource(res, R.mipmap.ic_launcher)) .setSmallIcon(R.drawable.stat_easynotification).setAutoCancel(true).setStyle(bts) .setColor(App.ACCENT_COLOR)//from w w w . java 2 s. c o m .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(id, builder.build()); }
From source file:com.parse.ParsePushUnityHelper.java
/** * A helper method that provides default behavior for handling ParsePushNotificationReceived. *///from w w w.j ava 2 s.c o m public static void handleParsePushNotificationReceived(Context context, String pushPayloadString) { try { JSONObject pushData = new JSONObject(pushPayloadString); if (pushData == null || (!pushData.has("alert") && !pushData.has("title"))) { return; } ManifestInfo info = new ManifestInfo(context); String title = pushData.optString("title", info.getDisplayName()); String alert = pushData.optString("alert", "Notification received."); String tickerText = title + ": " + alert; Random random = new Random(); int contentIntentRequestCode = random.nextInt(); Intent activityIntent = info.getLauncherIntent(); PendingIntent pContentIntent = PendingIntent.getActivity(context, contentIntentRequestCode, activityIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(alert).setTicker(tickerText).setSmallIcon(info.getPushIconId()) .setContentIntent(pContentIntent).setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL); Notification notification = builder.build(); NotificationManager manager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); int notificationId = (int) System.currentTimeMillis(); try { manager.notify(notificationId, notification); } catch (SecurityException se) { // Some phones throw exception for unapproved vibration. notification.defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND; manager.notify(notificationId, notification); } } catch (JSONException e) { // Do nothing. } }
From source file:ar.uba.fi.splitapp.MockServer.java
private static void showNotification(String header, String message, Bitmap icon) { Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(appContext) .setSmallIcon(R.drawable.logo).setLargeIcon(MockServer.getCircleBitmap(icon)) .setContentTitle(header).setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setColor(appContext.getResources().getColor(R.color.colorPrimaryLight)); NotificationManager notificationManager = (NotificationManager) appContext .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.scoreflex.ScoreflexGcmClient.java
protected static boolean onBroadcastReceived(Context context, Intent intent, int iconResource, Class<? extends Activity> activity) { Bundle extras = intent.getExtras();/*from www .j a va 2s. c o m*/ if (extras.isEmpty()) { // has effect of unparcelling Bundle return false; } String customDataJson = extras.getString(SCOREFLEX_CUSTOM_DATA_EXTRA_KEY); if (null == customDataJson) { return false; } try { JSONObject customData = new JSONObject(customDataJson); JSONObject data = customData.getJSONObject(SCOREFLEX_NOTIFICATION_EXTRA_KEY); JSONObject sfxData = data.optJSONObject("data"); if (data.getInt("code") < Scoreflex.NOTIFICATION_TYPE_CHALLENGE_INVITATION) { return false; } String targetPlayerId = sfxData.optString("targetPlayerId"); String loggedPlayerId = ScoreflexRestClient.getPlayerId(context); if (!targetPlayerId.equals(loggedPlayerId)) { return false; } PendingIntent pendingIntent = buildPendingIntent(data, context, activity); Notification notification = buildNotification(extras.getString("alert"), context, iconResource, pendingIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(data.getInt("code"), notification); intent.removeExtra(SCOREFLEX_CUSTOM_DATA_EXTRA_KEY); } catch (JSONException e1) { } return false; }
From source file:com.teinproductions.tein.papyrosprogress.UpdateCheckReceiver.java
private static void issueBlogNotification(Context context) { String title = context.getString(R.string.notification_title); String message = context.getString(R.string.blog_notification_content); PendingIntent pendingIntent;//from w w w . ja va2 s . c om try { pendingIntent = PendingIntent.getActivity(context, 0, new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.PAPYROS_BLOG_URL)), PendingIntent.FLAG_UPDATE_CURRENT); } catch (Exception e) { e.printStackTrace(); return; } NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(message).setContentIntent(pendingIntent) .setSmallIcon(R.mipmap.notification_small_icon) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)) .setDefaults(Notification.DEFAULT_ALL).setAutoCancel(true); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(BLOG_NOTIFICATION_ID, builder.build()); }
From source file:com.afrozaar.jazzfestreporting.ResumableUpload.java
private static void notifyFailedUpload(Context context, String message, NotificationManager notifyManager, NotificationCompat.Builder builder) { builder.setContentTitle(context.getString(R.string.yt_upload_failed)).setContentText(message); notifyManager.notify(UPLOAD_NOTIFICATION_ID, builder.build()); Log.e(ResumableUpload.class.getSimpleName(), message); }
From source file:Main.java
public static void notifyShort(@NonNull Context context, @NonNull String title, @NonNull String msg, @DrawableRes int iconId, int nId, @Nullable PendingIntent pendingIntent) { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new NotificationCompat.Builder(context).setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL).setContentTitle(title).setContentText(msg) .setSmallIcon(iconId).setContentIntent(pendingIntent).build(); notificationManager.notify(nId, notification); }