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:adapter.notification.MyFcmListenerService.java

private void sendNotification(RemoteMessage.Notification notification) {
    Intent intent = new Intent(this, MainActivity.class);
    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.ic_stat_utn).setContentTitle(notification.getTitle())
            .setContentText(notification.getBody()).setGroup(notification.getTag()).setAutoCancel(true)
            .setColor(ContextCompat.getColor(getApplicationContext(), R.color.caldroid_holo_blue_dark))
            .setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

    notificationManager.notify(0 /* ID of adapter.notification */, notificationBuilder.build());
}

From source file:com.chinatelecom.ctsi.workhelper.pushutil.Notify.java

/**
 * Displays a notification in the notification area of the UI
 * @param context Context from which to create the notification
 * @param messageString The string to display to the user as a message
 * @param intent The intent which will start the activity when the user clicks the notification
 * @param notificationTitle The resource reference to the notification title
 *//*from w  ww .  j  ava 2  s  .c  o m*/
public static void notifcation(Context context, String messageString, Intent intent, String title) {

    //Get the notification manage which we will use to display the notification
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);

    Calendar.getInstance().getTime().toString();

    long when = System.currentTimeMillis();

    //get the notification title from the application's strings.xml file
    // CharSequence contentTitle = context.getString(notificationTitle);

    //the message that will be displayed as the ticker
    String ticker = title + " " + messageString;

    //build the pending intent that will start the appropriate activity
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

    //build the notification
    Builder notificationCompat = new Builder(context);
    notificationCompat.setAutoCancel(true).setContentTitle(title).setContentIntent(pendingIntent)
            .setContentText(messageString).setTicker(ticker).setWhen(when).setSmallIcon(R.drawable.ic_launcher);

    Notification notification = notificationCompat.build();
    notification.defaults = Notification.DEFAULT_ALL;
    //display the notification
    mNotificationManager.notify(MessageID, notification);
    MessageID++;

}

From source file:biz.atelecom.communicator.MyGcmListenerService.java

private void sendNotification(Bundle data) {
    //Intent intent = new Intent(this, ChatActivity.class);
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtras(data);//  w w  w  .  j a v a2 s  .c om

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.atelecom_ic_notification).setContentTitle("Atelecom Message")
            .setContentText("message").setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:assistance.shopping.msc.assistant.support.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message shoppingBroadcastDescription received.
 *///  w ww . j  a va2s.com
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, LoginActivity.class);
    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.ic_stat_ic_notification).setContentTitle("FCM Message")
            .setContentText(messageBody).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:app.presentation.foundation.gcm.GcmReceiverBackground.java

private void showNotification(Message message, String title, String body, Application application) {
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(application)
            .setContentTitle(title).setContentText(body).setDefaults(Notification.DEFAULT_ALL)
            .setSmallIcon(R.mipmap.ic_launcher).setAutoCancel(true)
            .setContentIntent(getPendingIntentForNotification(message));

    NotificationManager notificationManager = (NotificationManager) application
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(1, notificationBuilder.build());
}

From source file:bhtech.com.cabbydriver.services.MyGcmListenerService.java

private void sendNotification(String message) {
    Intent intent = new Intent(this, ChooseRouteToCustomerController.class);
    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.ic_stat_ic_notification)
            .setContentTitle("GCM Message").setContentText(message).setAutoCancel(true)
            .setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:com.achep.acdisplay.notifications.NotificationListenerJellyBeanMR2.java

@Override
public void onListenerBind(@NonNull MediaService service) {
    mInitialized = false;/* www.  j  a v  a2  s  . c  om*/

    // What is the idea of init notification?
    // Well the main goal is to access #getActiveNotifications()
    // what seems to be not possible without dirty and buggy
    // workarounds.
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            MediaService service = MediaService.sService;
            if (service == null)
                return;

            Resources res = service.getResources();
            NotificationCompat.Builder builder = new NotificationCompat.Builder(service)
                    .setContentTitle(res.getString(R.string.app_name))
                    .setContentText(res.getString(R.string.notification_init_text))
                    .setSmallIcon(R.drawable.stat_notify).setPriority(Notification.PRIORITY_MIN)
                    .setAutoCancel(true).setColor(App.ACCENT_COLOR);

            String name = Context.NOTIFICATION_SERVICE;
            NotificationManager nm = (NotificationManager) service.getSystemService(name);
            nm.notify(App.ID_NOTIFY_INIT, builder.build());
        }
    }, 2000);
}

From source file:au.com.wallaceit.reddinator.MailCheckService.java

private void setNotification() {
    int message = global.mRedditData.getInboxCount();
    Intent notifyIntent = new Intent(this, WebViewActivity.class);
    notifyIntent.setAction(WebViewActivity.ACTION_CLEAR_INBOX_COUNT);
    notifyIntent.putExtra("url", "http://www.reddit.com/message/unread/.compact");
    Notification notification = new NotificationCompat.Builder(this).setContentTitle(message + " New Messages")
            .setContentText("Click to view reddit messages")
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.reddit_icon_small))
            .setSmallIcon(R.drawable.ic_notify)
            .setContentIntent(//from ww  w  . java 2 s.c  om
                    PendingIntent.getActivity(this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT))
            .build();

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(1, notification);
}

From source file:be.thomasave.executeorder42.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.// w  ww.j av  a2  s  .c om
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivity.class);
    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.icon).setContentTitle("Execute Order 42").setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:co.ommu.inlis.components.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*from   w  w  w .j  a v a 2s.c om*/
private void sendNotification(String messageBody) {

    Log.d(TAG, "Notification Message Body: " + messageBody);

    Intent intent = new Intent(this, MainActivity.class);
    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.mipmap.ic_launcher).setContentTitle("FCM Message").setContentText(messageBody)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}