Example usage for android.content Context NOTIFICATION_SERVICE

List of usage examples for android.content Context NOTIFICATION_SERVICE

Introduction

In this page you can find the example usage for android.content Context NOTIFICATION_SERVICE.

Prototype

String NOTIFICATION_SERVICE

To view the source code for android.content Context NOTIFICATION_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.app.NotificationManager for informing the user of background events.

Usage

From source file:Main.java

public static NotificationManager showNotification(Context context, String title, String message,
        String alertmessage, int icon, Class<?> forwordActivity) {
    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    // The PendingIntent to launch our activity if the user selects this
    // notification
    // PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
    // new Intent(context, forwordActivity), 0);
    // construct the Notification object.
    Notification noti = new Notification();
    noti.icon = icon;/*  ww  w.jav a 2 s .  co m*/
    noti.tickerText = alertmessage;
    noti.when = System.currentTimeMillis();

    // Set the info for the views that show in the notification panel.
    // noti.setLatestEventInfo(context, title, message, contentIntent);

    // after a 100ms delay, vibrate for 250ms, pause for 100 ms and
    // then vibrate for 500ms.
    noti.vibrate = new long[] { 100, 250, 100, 500 };

    // Note that we use R.layout.incoming_message_panel as the ID for
    // the notification. It could be any integer you want, but we use
    // the convention of using a resource id for a string related to
    // the notification. It will always be a unique number within your
    // application.
    nm.notify(1, noti);
    return nm;
}

From source file:Main.java

public static void updateNotification(Context context, int notifiId, Notification notification) {
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(notifiId, notification);
}

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));
    }/*  w  w w. ja va 2 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:Main.java

/**
 * This method stops the tracking notification for the user.
 * // w  ww. j  a v  a  2 s  . c  om
 * @param activity
 *            The activity from which the method called.
 */
public static void stopUserNotification(Activity activity) {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) activity.getSystemService(ns);
    mNotificationManager.cancel(TRACKING_NOTIFY_ID);

}

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);//  ww w .  jav  a  2s.  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:Main.java

public static void cancel(Context c, int notifyId) {
    ((NotificationManager) ((Activity) c).getSystemService(Context.NOTIFICATION_SERVICE)).cancel(notifyId);
}

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);
}

From source file:MainActivity.java

public void clickLightsActionSound(View view) {

    NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Uri notificationSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("LightsActionSoundRedux")
            .setContentText("Lights, Action & Sound").setSound(notificationSoundUri)
            .setLights(Color.BLUE, 500, 500).setVibrate(new long[] { 250, 500, 250, 500, 250, 500 });
    notificationManager.notify(0, notificationBuilder.build());

}

From source file:com.manning.androidhacks.hack046.helper.NotificationHelper.java

public static void showMsgNotification(Context ctx) {
    final NotificationManager mgr;
    mgr = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx)
            .setSmallIcon(android.R.drawable.sym_def_app_icon).setTicker("New msg!")
            .setContentTitle("This is the msg title").setContentText("content...")
            .setContentIntent(getPendingIntent(ctx));

    builder.addAction(android.R.drawable.ic_menu_send, ctx.getString(R.string.activity_msg_button_reply),
            getReplyPendingIntent(ctx));

    builder.addAction(android.R.drawable.ic_menu_delete, ctx.getString(R.string.activity_msg_button_delete),
            getDeletePendingIntent(ctx));

    mgr.notify(R.id.activity_main_receive_msg, builder.build());
}

From source file:GCMService.java

private void sendNotification(String message) {
    Log.i("GCMService", "sendNotification()");
    Uri notificationSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("GCM Message").setContentText(message)
            .setSound(notificationSoundUri).setLights(Color.BLUE, 500, 500);
    NotificationManager notificationManager = (NotificationManager) getApplicationContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notificationBuilder.build());
}