Example usage for android.app NotificationManager notify

List of usage examples for android.app NotificationManager notify

Introduction

In this page you can find the example usage for android.app NotificationManager notify.

Prototype

public void notify(int id, Notification notification) 

Source Link

Document

Post a notification to be shown in the status bar.

Usage

From source file:Main.java

public static void sendExtendedNotification(Context context, String smTitle, String smMsg,
        ArrayList<String> lgMsg) {

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(android.R.drawable.alert_light_frame).setContentTitle(smTitle).setContentText(smMsg);

    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

    // Sets a title for the Inbox in expanded layout
    inboxStyle.setBigContentTitle(smTitle);

    // Moves events into the expanded layout
    for (int i = 0; i < lgMsg.size(); i++) {
        inboxStyle.addLine(lgMsg.get(i));
    }/*from w ww . j  a  va2  s  . c o m*/

    // Moves the expanded layout object into the notification object.
    mBuilder.setStyle(inboxStyle);

    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    //Update the ID entered if it exists, create a new one if it doesn't
    mNotificationManager.notify(notifyId, mBuilder.build());

    notifyId++;
}

From source file:com.breadwallet.tools.manager.BRNotificationManager.java

public static void sendNotification(Activity ctx, int icon, String title, String message, int mId) {
    if (ctx == null)
        return;/*from  ww  w  .  java 2 s  .  c  o  m*/
    android.support.v4.app.NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx)
            .setSmallIcon(icon).setContentTitle(title).setContentText(message);
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(ctx, MainActivity.class);

    // The stack builder object will contain an artificial back stack for the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(ctx);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) ctx
            .getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(mId, mBuilder.build());
}

From source file:com.ademsha.appnotifico.NotificationHelper.java

public static void notify(PreparedNotification preparedNotification) {

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(preparedNotification.getContext())
            .setPriority(NotificationCompat.PRIORITY_DEFAULT).setOngoing(false).setAutoCancel(true)
            .setOnlyAlertOnce(true);/*w  w  w.ja va  2s. com*/

    builder.setContentTitle(preparedNotification.getTitle());
    builder.setContentText(preparedNotification.getText());
    if (preparedNotification.getLargeIcon() != null) {
        builder.setLargeIcon(preparedNotification.getLargeIcon());
    }
    if (preparedNotification.getSmallIcon() > 0) {
        builder.setSmallIcon(preparedNotification.getSmallIcon());
    }
    builder.setTicker(preparedNotification.getTicker());

    if (!preparedNotification.getExpanded().equals("")
            && !preparedNotification.getExpandedSummary().equals("")) {
        builder.setStyle(new NotificationCompat.BigTextStyle().bigText(preparedNotification.getExpanded())
                .setBigContentTitle(preparedNotification.getTitle())
                .setSummaryText(preparedNotification.getExpandedSummary()));
    }

    if (preparedNotification.getPendingIntentForActivity() != null) {
        builder.setContentIntent(preparedNotification.getPendingIntentForActivity());
    }

    NotificationManager notificationManager = (NotificationManager) preparedNotification.getContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(preparedNotification.getId(), builder.build());

}

From source file:Main.java

public static void showNotification(long id, String titleString, String messageString, int iconResId,
        Context context, Class<?> className) {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setSmallIcon(iconResId)
            .setContentTitle(titleString).setStyle(new NotificationCompat.BigTextStyle().bigText(messageString))
            .setContentText(messageString);
    Intent intent = new Intent(context, className);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(className);
    stackBuilder.addNextIntent(intent);/*from   w ww . j  av  a2 s.  c  o  m*/
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = mBuilder.build();
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    mNotificationManager.notify((int) id, notification);
}

From source file:com.codefupanda.app.swish.util.NotificationUtil.java

/**
 * Show notification./* w  ww .  ja v  a 2s. c o m*/
 * 
 * @param context
 */
public static void showNotification(final Context context) {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(context.getText(R.string.notification_title))
            .setContentText(context.getText(R.string.notification_text)).setSound(soundUri);

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, MainActivity.class);

    // The stack builder object will contain an artificial back stack for
    // the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.class);

    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    // mId allows you to update the notification later on.
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:org.lol.reddit.receivers.NewMessageChecker.java

private static void createNotification(String title, String text, Context context) {

    final NotificationCompat.Builder notification = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.icon_inv).setContentTitle(title).setContentText(text).setAutoCancel(true);

    final Intent intent = new Intent(context, InboxListingActivity.class);
    notification.setContentIntent(PendingIntent.getActivity(context, 0, intent, 0));

    final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(0, notification.getNotification());
}

From source file:ca.rmen.android.networkmonitor.app.service.NetMonNotification.java

/**
 * Shows a notification with the given ticker text and content text. The icon is a warning icon, and the notification title is the app name. Tapping on the
 * notification opens the given activity.
 *//*  w  ww. jav a2  s . co  m*/
private static void showNotification(Context context, int notificationId, int tickerTextId, int contentTextId,
        Class<?> activityClass) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setSmallIcon(R.drawable.ic_stat_warning);
    builder.setAutoCancel(true);
    builder.setTicker(context.getString(tickerTextId));
    builder.setContentTitle(context.getString(R.string.app_name));
    builder.setContentText(context.getString(contentTextId));
    builder.setAutoCancel(false);
    Uri uri = NetMonPreferences.getInstance(context).getNotificationSoundUri();
    builder.setSound(uri);
    builder.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, activityClass),
            PendingIntent.FLAG_UPDATE_CURRENT));
    Notification notification = builder.build();
    notification.flags |= Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_ONLY_ALERT_ONCE;
    notification.ledARGB = 0xFFffff00;
    notification.ledOnMS = 300;
    notification.ledOffMS = 2000;
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(notificationId, notification);
}

From source file:com.banana.instagrab.helper.NotificationUtils.java

public static void remindUserBecauseCharging(Context context) {
    // COMPLETED (8) In the remindUser method use NotificationCompat.Builder to create a notification
    // that:/*from   w w  w.  jav  a2  s. c  om*/
    // - has a color of R.colorPrimary - use ContextCompat.getColor to get a compatible color
    // - has ic_drink_notification as the small icon
    // - uses icon returned by the largeIcon helper method as the large icon
    // - sets the title to the charging_reminder_notification_title String resource
    // - sets the text to the charging_reminder_notification_body String resource
    // - sets the style to NotificationCompat.BigTextStyle().bigText(text)
    // - sets the notification defaults to vibrate
    // - uses the content intent returned by the contentIntent helper method for the contentIntent
    // - automatically cancels the notification when the notification is clicked
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            //.setColor(ContextCompat.getColor(context, R.color.colorPrimary))
            //.setSmallIcon(R.drawable.ic_drink_notification)
            //.setLargeIcon(largeIcon(context))
            .setContentTitle("?!").setContentText("?!")
            //.setStyle(new NotificationCompat.MessagingStyle.Message()
            .setDefaults(Notification.DEFAULT_VIBRATE).setContentIntent(contentIntent(context))
            .setAutoCancel(false);

    Log.d("hahaha", "1");

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        notificationBuilder.setPriority(Notification.PRIORITY_HIGH);
    }
    Log.d("hahaha", "2");
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Log.d("hahaha", "3");
    notificationManager.notify(WATER_REMINDER_NOTIFICATION_ID, notificationBuilder.build());
    Log.d("hahaha", "4");
}

From source file:ca.rmen.android.poetassistant.wotd.Wotd.java

static void notifyWotd(Context context, Dictionary dictionary) {
    Log.v(TAG, "notifyWotd");
    DictionaryEntry entry = dictionary.getRandomEntry(getTodayUTC().getTimeInMillis());
    if (entry == null)
        return;//w w  w .  j a v a2s  .c  om
    String title = context.getString(R.string.wotd_notification_title, entry.word);
    CharSequence content = buildWotdNotificationContent(context, entry);
    NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle().bigText(content);
    Uri uri = Uri.parse(String.format("poetassistant://%s/%s", Constants.DEEP_LINK_QUERY, entry.word));
    Intent intent = new Intent(context, MainActivity.class).setAction(Intent.ACTION_VIEW).setData(uri)
            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
    int iconId = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? R.drawable.ic_book_vector
            : R.drawable.ic_book;
    Notification notification = new NotificationCompat.Builder(context).setAutoCancel(true)
            .setContentIntent(pendingIntent).setContentText(content).setContentTitle(title).setSmallIcon(iconId)
            .setStyle(bigTextStyle)
            .addAction(getShareIconId(), context.getString(R.string.share), getShareIntent(context, entry))
            .build();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(TAG.hashCode(), notification);
}

From source file:com.cmput301w17t07.moody.AchievementController.java

/**
 * this method is used to send a notification to the android phone once a achievement has been
 * unlocked and then displays the information of the achievement <br>
 * @param context <br>// www.  j  a v  a 2  s  .  c o m
 * @param achievement <br>
 */
public static void displayAchievement(Context context, String achievement) {
    NotificationCompat.Builder b = new NotificationCompat.Builder(context);
    b.setAutoCancel(true).setDefaults(NotificationCompat.DEFAULT_ALL).setWhen(System.currentTimeMillis())
            .setSmallIcon(R.drawable.achievement2).setTicker("{your tiny message}").setContentTitle("Moody")
            .setContentText(achievement).setContentInfo("INFO").setPriority(Notification.PRIORITY_MAX);

    NotificationManager nm = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
    nm.notify(1, b.build());
}