Example usage for android.support.v4.app NotificationManagerCompat from

List of usage examples for android.support.v4.app NotificationManagerCompat from

Introduction

In this page you can find the example usage for android.support.v4.app NotificationManagerCompat from.

Prototype

public static NotificationManagerCompat from(Context context) 

Source Link

Usage

From source file:Main.java

public static void cancelAll(Context context) {
    NotificationManagerCompat nm = NotificationManagerCompat.from(context);
    nm.cancelAll();
}

From source file:com.bobomee.android.common.util.NotificationUtil.java

/**
 * ??/*ww  w.  ja va  2  s . c  om*/
 */
public static NotificationManagerCompat initService(Context mContext) {
    NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(mContext);
    return mNotificationManager;
}

From source file:com.ezhuk.wear.NotificationUtils.java

public static void showNotification(Context context) {
    NotificationManagerCompat.from(context).notify(getNewID(), createBasicNotificationBuilder(context).build());
}

From source file:com.ezhuk.wear.NotificationUtils.java

public static void showNotificationNoIcon(Context context) {
    NotificationManagerCompat.from(context).notify(getNewID(), createBasicNotificationBuilder(context)
            .extend(new WearableExtender().setHintHideIcon(true)).build());
}

From source file:com.benext.thibault.appsample.notification.builder.NotificationBuilder.java

public static void sendNotification(Context context, NotificationCompat.Builder builder) {
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
    notificationManager.notify(NOTIFICATION_ID++, builder.build());
}

From source file:com.ezhuk.wear.NotificationUtils.java

private static void showNotificationWithPriority(Context context, int id, int priority) {
    NotificationManagerCompat.from(context).notify(id,
            createBasicNotificationBuilder(context).setPriority(priority).build());
}

From source file:cheaphone.core.Notification.java

public static void showNotification(Context c, String text) {
    int notificationId = 001;
    // Build intent for notification content
    Intent viewIntent = new Intent(c, MainActivity.class);
    viewIntent.putExtra("0", 1);
    PendingIntent viewPendingIntent = PendingIntent.getActivity(c, 0, viewIntent, 0);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(c)
            .setLargeIcon(/*from  ww  w  .  j av  a2 s  .c  om*/
                    ((BitmapDrawable) c.getResources().getDrawable(R.drawable.ic_notification)).getBitmap())
            .setSmallIcon(R.drawable.ic_notification)
            //.setColor(0)
            .setContentTitle(Constants.applicationName).setContentText(text).setContentIntent(viewPendingIntent)
            .setAutoCancel(true);
    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(c);

    // Build the notification and issues it with notification manager.
    notificationManager.notify(notificationId, notificationBuilder.build());
}

From source file:com.commonsware.android.messaging.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    NotificationManagerCompat.from(this).notify(RemoteInputReceiver.NOTIFY_ID,
            RemoteInputReceiver.buildNotification(this).build());

    finish();/*  www.jav  a2 s  .  co m*/
}

From source file:fr.shywim.antoinedaniel.utils.NotifUtils.java

/**
 * Send a notification to the device. Support for weareable extension.
 *
 * @param id Notification id, must be one of {@link #NOTIFICATION_NEW_VIDEO},
 * {@link #NOTIFICATION_NEW_SOUNDS} or {@link #NOTIFICATION_OTHER}.
 * @param context A {@link android.content.Context}.
 * @param msg Notification's message./*from w  w  w  . ja  v a 2 s  .  co m*/
 * @param ytLink A youtube video id (optionnal).
 */
public static void sendNotification(@NotificationId final int id, final Context context, final String msg,
        @Nullable final String ytLink) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.ic_notifs)
                    .setContentTitle(context.getString(R.string.notifications)).setContentText(msg)
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setAutoCancel(true);

            switch (id) {
            case NOTIFICATION_NEW_VIDEO:
                builder.setContentTitle("Nouvelle vido !").setContentText(msg);
                break;

            case NOTIFICATION_NEW_SOUNDS:
                builder.setContentTitle("Nouveaux extraits !").setContentText(msg);
                break;

            case NOTIFICATION_OTHER:
                builder.setContentTitle("La Bote  Antoine Daniel").setContentText(msg);
                break;
            }

            builder.setPriority(NotificationCompat.PRIORITY_LOW);
            if (PrefUtils.getNotifSoundEnabled(context)) {
                builder.setSound(Uri.parse(PrefUtils.getNotifRingtone(context)));
            }
            if (PrefUtils.getNotifLightsEnabled(context)) {
                builder.setDefaults(Notification.DEFAULT_LIGHTS);
            }

            Bitmap wearableBitmap;

            PendingIntent contentIntent;
            if (ytLink != null) {
                String bitmapLink = context.getString(R.string.api_get_yt_thmb) + ytLink;

                try {
                    wearableBitmap = Picasso.with(context).load(bitmapLink).resize(400, 400).centerCrop().get();
                } catch (IOException e) {
                    // If we can't download the video image, set the default notification bitmap
                    e.printStackTrace();
                    wearableBitmap = BitmapFactory.decodeResource(context.getResources(),
                            R.drawable.weareable_default_background);
                }

                String url = context.getString(R.string.youtube_link_prefix) + ytLink;
                contentIntent = PendingIntent.getActivity(context, 0,
                        new Intent(Intent.ACTION_VIEW, Uri.parse(url)), 0);
            } else {
                wearableBitmap = BitmapFactory.decodeResource(context.getResources(),
                        R.drawable.weareable_default_background);

                contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class),
                        0);
            }

            WearableExtender wearableExtender = new WearableExtender().setHintHideIcon(true)
                    .setBackground(wearableBitmap);

            builder.setContentIntent(contentIntent).setLargeIcon(wearableBitmap).extend(wearableExtender);

            notificationManager.notify(id, builder.build());
        }
    }).start();
}

From source file:com.onesignal.NotificationOpenedProcessor.java

public static void processFromActivity(Context inContext, Intent inIntent) {
    // Pressed an action button, need to clear the notification and close the notification area manually.
    if (inIntent.getBooleanExtra("action_button", false)) {
        NotificationManagerCompat.from(inContext).cancel(inIntent.getIntExtra("notificationId", 0));
        inContext.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
    }/*w ww  .ja v  a 2s  .  c  om*/

    processIntent(inContext, inIntent);
}