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:com.geecko.QuickLyric.broadcastReceiver.WearableRequestReceiver.java

@Override
public void onLyricsDownloaded(Lyrics lyrics) {
    if (lyrics.isLRC()) {
        LrcView lrcView = new LrcView(mContext, null);
        lrcView.setOriginalLyrics(lyrics);
        lrcView.setSourceLrc(lyrics.getText());
        lyrics.setText(lrcView.getStaticLyrics().getText());
    }/*w ww. j  a  va2s  .  co m*/

    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(mContext);
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(mContext);

    Intent activityIntent = new Intent("com.geecko.QuickLyric.getLyrics").putExtra("TAGS",
            new String[] { lyrics.getArtist(), lyrics.getTitle() });
    PendingIntent openAction = PendingIntent.getActivity(mContext, 0, activityIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    BigTextStyle bigStyle = new BigTextStyle();
    bigStyle.bigText(lyrics.getText() != null ? Html.fromHtml(lyrics.getText()) : "");

    int[] themes = new int[] { R.style.Theme_QuickLyric, R.style.Theme_QuickLyric_Red,
            R.style.Theme_QuickLyric_Purple, R.style.Theme_QuickLyric_Indigo, R.style.Theme_QuickLyric_Green,
            R.style.Theme_QuickLyric_Lime, R.style.Theme_QuickLyric_Brown, R.style.Theme_QuickLyric_Dark };
    int themeNum = Integer.valueOf(sharedPref.getString("pref_theme", "0"));
    int notificationPref = Integer.valueOf(sharedPref.getString("pref_notifications", "0"));

    TypedValue primaryColorValue = new TypedValue();
    mContext.setTheme(themes[themeNum]);
    mContext.getTheme().resolveAttribute(R.attr.colorPrimary, primaryColorValue, true);

    notifBuilder.setSmallIcon(R.drawable.ic_notif).setContentTitle(mContext.getString(R.string.app_name))
            .setContentText(String.format("%s - %s", lyrics.getArtist(), lyrics.getTitle())).setStyle(bigStyle)
            .setGroup("Lyrics_Notification").setOngoing(false).setColor(primaryColorValue.data)
            .setGroupSummary(false).setContentIntent(openAction).setVisibility(-1); // Notification.VISIBILITY_SECRET

    if (notificationPref == 2)
        notifBuilder.setPriority(-2);

    if (lyrics.getFlag() < 0)
        notifBuilder.extend(new NotificationCompat.WearableExtender().setContentIntentAvailableOffline(false));

    Notification notif = notifBuilder.build();

    NotificationManagerCompat.from(mContext).notify(8, notif);
}

From source file:com.google.android.apps.santatracker.WearNotificationService.java

@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    Log.v(TAG, "onDataChanged");
    for (DataEvent dataEvent : dataEvents) {
        if (dataEvent.getType() == DataEvent.TYPE_CHANGED) {
            DataMap dataMap = DataMapItem.fromDataItem(dataEvent.getDataItem()).getDataMap();
            String content = dataMap.getString(NotificationConstants.KEY_CONTENT);
            String path = dataEvent.getDataItem().getUri().getPath();
            if (NotificationConstants.TAKEOFF_PATH.equals(path)) {
                Log.v(TAG, "building takeoff notification");
                buildTakeoffNotification(content);
            }//ww w  . java  2 s. c o  m
        } else if (dataEvent.getType() == DataEvent.TYPE_DELETED) {
            // There's only one notification shown at a time, so just dismiss it.
            NotificationManagerCompat.from(this).cancelAll();
        }
    }
}

From source file:conversandroid.cookingnotifications.MainActivity.java

/**
 * Simple notification: only title and text, no actions attached
 *///from ww w.  ja va  2 s.  c  om
private void showSimpleNotification() {
    int notificationId = 1;

    //Building notification layout
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.cook).setContentTitle("Time for lunch!")
            .setDefaults(Notification.DEFAULT_ALL) //Beware that without some default behaviours
            //the notification may not show up in the wearable
            .setContentText("Your lunch is ready");

    //Creating an instance of the NotificationManager service
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

    // Building the notification and issuing it with the notification manager
    notificationManager.notify(notificationId, notificationBuilder.build());

}

From source file:com.morlunk.mumbleclient.service.PlumbleReconnectNotification.java

public void show(String error, boolean autoReconnect) {
    IntentFilter filter = new IntentFilter();
    filter.addAction(BROADCAST_DISMISS);
    filter.addAction(BROADCAST_RECONNECT);
    filter.addAction(BROADCAST_CANCEL_RECONNECT);
    try {/*from  ww w .j  a  v  a2  s . c o  m*/
        mContext.registerReceiver(mNotificationReceiver, filter);
    } catch (IllegalArgumentException e) {
        // Thrown if receiver is already registered.
        e.printStackTrace();
    }
    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
    builder.setSmallIcon(R.drawable.ic_stat_notify);
    builder.setPriority(NotificationCompat.PRIORITY_MAX);
    builder.setDefaults(NotificationCompat.DEFAULT_VIBRATE | NotificationCompat.DEFAULT_LIGHTS);
    builder.setContentTitle(mContext.getString(R.string.plumbleDisconnected));
    builder.setContentText(error);
    builder.setTicker(mContext.getString(R.string.plumbleDisconnected));

    Intent dismissIntent = new Intent(BROADCAST_DISMISS);
    builder.setDeleteIntent(
            PendingIntent.getBroadcast(mContext, 2, dismissIntent, PendingIntent.FLAG_CANCEL_CURRENT));

    if (autoReconnect) {
        Intent cancelIntent = new Intent(BROADCAST_CANCEL_RECONNECT);
        builder.addAction(R.drawable.ic_action_delete_dark, mContext.getString(R.string.cancel_reconnect),
                PendingIntent.getBroadcast(mContext, 2, cancelIntent, PendingIntent.FLAG_CANCEL_CURRENT));
        builder.setOngoing(true);
    } else {
        Intent reconnectIntent = new Intent(BROADCAST_RECONNECT);
        builder.addAction(R.drawable.ic_action_move, mContext.getString(R.string.reconnect),
                PendingIntent.getBroadcast(mContext, 2, reconnectIntent, PendingIntent.FLAG_CANCEL_CURRENT));
    }

    NotificationManagerCompat nmc = NotificationManagerCompat.from(mContext);
    nmc.notify(NOTIFICATION_ID, builder.build());
}

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

public static void showNotificationWithInputForPrimaryAction(Context context) {
    Intent intent = new Intent(ACTION_TEST);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

    RemoteInput remoteInput = new RemoteInput.Builder(ACTION_EXTRA)
            .setLabel(context.getString(R.string.action_label))
            .setChoices(context.getResources().getStringArray(R.array.input_choices)).build();

    NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_launcher, "Action",
            pendingIntent).addRemoteInput(remoteInput).build();

    NotificationManagerCompat.from(context).notify(getNewID(),
            new NotificationCompat.Builder(context).setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle(context.getString(R.string.action_title))
                    .setContentText(context.getString(R.string.action_text)).setContentIntent(pendingIntent)
                    .extend(new WearableExtender().addAction(action)).build());
}

From source file:at.bitfire.davdroid.syncadapter.SyncManager.java

public SyncManager(Context context, Account account, AccountSettings settings, Bundle extras, String authority,
        SyncResult syncResult, String uniqueCollectionId) throws InvalidAccountException {
    this.context = context;
    this.account = account;
    this.settings = settings;
    this.extras = extras;
    this.authority = authority;
    this.syncResult = syncResult;

    // create HttpClient with given logger
    httpClient = HttpClient.create(context, account);

    // dismiss previous error notifications
    this.uniqueCollectionId = uniqueCollectionId;
    notificationManager = NotificationManagerCompat.from(context);
    notificationManager.cancel(uniqueCollectionId, notificationId());
}

From source file:com.androidinspain.deskclock.alarms.AlarmNotifications.java

static synchronized void showLowPriorityNotification(Context context, AlarmInstance instance) {
    LogUtils.v("Displaying low priority notification for alarm instance: " + instance.mId);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setShowWhen(false)
            .setContentTitle(//  w  ww .j  av a 2  s  .  com
                    context.getString(com.androidinspain.deskclock.R.string.alarm_alert_predismiss_title))
            .setContentText(AlarmUtils.getAlarmText(context, instance, true /* includeLabel */))
            .setColor(ContextCompat.getColor(context, com.androidinspain.deskclock.R.color.default_background))
            .setSmallIcon(com.androidinspain.deskclock.R.drawable.stat_notify_alarm).setAutoCancel(false)
            .setSortKey(createSortKey(instance)).setPriority(NotificationCompat.PRIORITY_DEFAULT)
            .setCategory(NotificationCompat.CATEGORY_ALARM).setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setLocalOnly(true);

    if (Utils.isNOrLater()) {
        builder.setGroup(UPCOMING_GROUP_KEY);
    }

    // Setup up hide notification
    Intent hideIntent = AlarmStateManager.createStateChangeIntent(context, AlarmStateManager.ALARM_DELETE_TAG,
            instance, AlarmInstance.HIDE_NOTIFICATION_STATE);
    final int id = instance.hashCode();
    builder.setDeleteIntent(
            PendingIntent.getService(context, id, hideIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    // Setup up dismiss action
    Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context,
            AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.PREDISMISSED_STATE);
    builder.addAction(com.androidinspain.deskclock.R.drawable.ic_alarm_off_24dp,
            context.getString(com.androidinspain.deskclock.R.string.alarm_alert_dismiss_text),
            PendingIntent.getService(context, id, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    // Setup content action if instance is owned by alarm
    Intent viewAlarmIntent = createViewAlarmIntent(context, instance);
    builder.setContentIntent(
            PendingIntent.getActivity(context, id, viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    NotificationManagerCompat nm = NotificationManagerCompat.from(context);
    final Notification notification = builder.build();
    nm.notify(id, notification);
    updateUpcomingAlarmGroupNotification(context, -1, notification);
}

From source file:org.telegram.messenger.LocationSharingService.java

private void updateNotification(boolean post) {
    if (builder == null) {
        return;//from   w w  w.j  a  va  2  s  .c  o m
    }
    String param;
    ArrayList<LocationController.SharingLocationInfo> infos = getInfos();
    if (infos.size() == 1) {
        LocationController.SharingLocationInfo info = infos.get(0);
        int lower_id = (int) info.messageObject.getDialogId();
        int currentAccount = info.messageObject.currentAccount;
        if (lower_id > 0) {
            TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(lower_id);
            param = UserObject.getFirstName(user);
        } else {
            TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-lower_id);
            if (chat != null) {
                param = chat.title;
            } else {
                param = "";
            }
        }
    } else {
        param = LocaleController.formatPluralString("Chats", infos.size());
    }
    String str = String.format(
            LocaleController.getString("AttachLiveLocationIsSharing", R.string.AttachLiveLocationIsSharing),
            LocaleController.getString("AttachLiveLocation", R.string.AttachLiveLocation), param);
    builder.setTicker(str);
    builder.setContentText(str);
    if (post) {
        NotificationManagerCompat.from(ApplicationLoader.applicationContext).notify(6, builder.build());
    }
}

From source file:org.hermes.android.NotificationsController.java

public NotificationsController() {
    notificationManager = NotificationManagerCompat.from(ApplicationLoader.applicationContext);
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications",
            Context.MODE_PRIVATE);
    inChatSoundEnabled = preferences.getBoolean("EnableInChatSound", true);

    try {/*from  w  w w.  ja v  a2s  .  c  o m*/
        audioManager = (AudioManager) ApplicationLoader.applicationContext
                .getSystemService(Context.AUDIO_SERVICE);
        //mediaPlayer = new MediaPlayer();
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}

From source file:id.satusatudua.sigap.service.EmergencyService.java

private void showEmergencyButton() {
    PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0,
            TombolActivity.generateIntent(this, true), PendingIntent.FLAG_UPDATE_CURRENT);
    RemoteViews views = new RemoteViews(getPackageName(), R.layout.notification_emergency_button);

    Notification notification = new NotificationCompat.Builder(getApplicationContext())
            .setSmallIcon(R.mipmap.ic_launcher).setContent(views).setOngoing(true)
            .setContentIntent(pendingIntent).setAutoCancel(false).build();

    NotificationManagerCompat.from(SigapApp.pluck().getApplicationContext()).notify(696961, notification);
}