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:org.isoron.uhabits.notifications.NotificationTray.java

public void cancel(@NonNull Habit habit) {
    int notificationId = getNotificationId(habit);
    NotificationManagerCompat.from(context).cancel(notificationId);
    active.remove(habit);
}

From source file:com.androidinspain.deskclock.data.StopwatchModel.java

StopwatchModel(Context context, SharedPreferences prefs, NotificationModel notificationModel) {
    mContext = context;//  w  ww .  j a v a2 s  .  c  o m
    mPrefs = prefs;
    mNotificationModel = notificationModel;
    mNotificationManager = NotificationManagerCompat.from(context);

    // Update stopwatch notification when locale changes.
    final IntentFilter localeBroadcastFilter = new IntentFilter(Intent.ACTION_LOCALE_CHANGED);
    mContext.registerReceiver(mLocaleChangedReceiver, localeBroadcastFilter);
}

From source file:com.example.android.synchronizednotifications.DismissListener.java

@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent dataEvent : dataEvents) {
        if (dataEvent.getType() == DataEvent.TYPE_DELETED) {
            if (Constants.BOTH_PATH.equals(dataEvent.getDataItem().getUri().getPath())) {
                // notification on the phone should be dismissed
                NotificationManagerCompat.from(this).cancel(Constants.BOTH_ID);
            }/*from  www .ja v  a  2 s .  c o  m*/
        }
    }
}

From source file:org.linuxac.bilal.BilalAlarm.java

@Override
public void onReceive(Context context, Intent intent) {
    String message = intent.getStringExtra(BilalActivity.NOTIFY_MESSAGE);

    Log.d(BilalActivity.TAG, "Alarm is ON: " + message);

    // Play athan
    Intent audioIntent = new Intent(context, AthanAudio.class);
    context.startService(audioIntent);//from  w ww.  j  av a 2s.  co  m

    // Build intent for notification content
    int notificationId = 0;
    int eventId = 0;
    Intent nextPrayerIntent = new Intent(context, BilalActivity.class);
    nextPrayerIntent.putExtra(EXTRA_EVENT_ID, eventId);
    PendingIntent nextPrayerPendingIntent = PendingIntent.getActivity(context, 0, nextPrayerIntent, 0);

    // Use another intent to stop athan from notification button
    PendingIntent cancelAthanPendingIntent = CancelAthanActivity.getCancelAthanIntent(notificationId, context);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(BilalActivity.TAG).setContentText(message)
            .setContentIntent(nextPrayerPendingIntent).setCategory(NotificationCompat.CATEGORY_ALARM)
            .setAutoCancel(true).setDeleteIntent(cancelAthanPendingIntent)
            .addAction(R.drawable.ic_clear, "? ", cancelAthanPendingIntent);

    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

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

    // ask Activity to update display to next prayer. TODO: delay highlighting of next prayer
    Intent updateIntent = new Intent(BilalActivity.UPDATE_MESSAGE);
    context.sendBroadcast(updateIntent);
}

From source file:com.android.deskclock.data.StopwatchModel.java

StopwatchModel(Context context, NotificationModel notificationModel) {
    mContext = context;//from   ww w.  ja v  a 2 s  .c o  m
    mNotificationModel = notificationModel;
    mNotificationManager = NotificationManagerCompat.from(context);

    // Update stopwatch notification when locale changes.
    final IntentFilter localeBroadcastFilter = new IntentFilter(Intent.ACTION_LOCALE_CHANGED);
    mContext.registerReceiver(mLocaleChangedReceiver, localeBroadcastFilter);
}

From source file:com.hodor.company.areminder.service.TimerService.java

private void removeAlarm() {
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.cancel(1);// ww w .  j a va 2  s.c  om

    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    Intent intent = new Intent(MainActivity.ACTION_SHOW_ALARM, null, this, TimerService.class);
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    alarmManager.cancel(pendingIntent);
}

From source file:net.frakbot.fweather.WearService.java

private void showNotification() {
    Intent notificationIntent = new Intent(this, WeatherActivity.class);
    PendingIntent notificationPendingIntent = PendingIntent.getActivity(this, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender()
            .setDisplayIntent(notificationPendingIntent)
            .addAction(new NotificationCompat.Action(android.R.drawable.ic_menu_share,
                    getString(R.string.share), createAppPendingIntent(this)))
            .setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.sky));

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("FWeather update").extend(wearableExtender);

    Notification notification = builder.build();

    NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
    notificationManagerCompat.notify(1, notification);
}

From source file:com.irccloud.android.RemoteInputService.java

@Override
protected void onHandleIntent(Intent intent) {
    boolean success = false;
    String sk = getSharedPreferences("prefs", 0).getString("session_key", "");
    if (intent != null && sk != null && sk.length() > 0) {
        final String action = intent.getAction();
        if (ACTION_REPLY.equals(action)) {
            Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
            if (remoteInput != null || intent.hasExtra("reply")) {
                Crashlytics.log(Log.INFO, "IRCCloud", "Got reply from RemoteInput");
                String reply = remoteInput != null ? remoteInput.getCharSequence("extra_reply").toString()
                        : intent.getStringExtra("reply");
                if (reply.length() > 0 && !reply.contains("\n/")
                        && (!reply.startsWith("/") || reply.toLowerCase().startsWith("/me ")
                                || reply.toLowerCase().startsWith("/slap "))) {
                    try {
                        JSONObject o = NetworkConnection.getInstance().say(intent.getIntExtra("cid", -1),
                                intent.getStringExtra("to"), reply, sk);
                        success = o.getBoolean("success");
                    } catch (Exception e) {
                        e.printStackTrace();
                    }/*w  w w  . j av a  2 s.  co  m*/
                }
                NotificationManagerCompat.from(IRCCloudApplication.getInstance().getApplicationContext())
                        .cancel(intent.getIntExtra("bid", 0));
                if (intent.hasExtra("eids")) {
                    int bid = intent.getIntExtra("bid", -1);
                    long[] eids = intent.getLongArrayExtra("eids");
                    for (int j = 0; j < eids.length; j++) {
                        if (eids[j] > 0) {
                            Notifications.getInstance().dismiss(bid, eids[j]);
                        }
                    }
                }
                if (!success)
                    Notifications.getInstance().alert(intent.getIntExtra("bid", -1), "Sending Failed",
                            reply.startsWith("/") ? "Please launch the IRCCloud app to send this command"
                                    : "Your message was not sent. Please try again shortly.");
            } else {
                Crashlytics.log(Log.ERROR, "IRCCloud", "RemoteInputService received no remoteinput");
            }
        }
    }
}

From source file:com.google.android.apps.santatracker.notification.SantaNotificationBuilder.java

/**
 * Display a generic Santa notification with content loaded from a string resource.
 *//*  ww w.j  a  va  2s  .c o m*/
public static void CreateSantaNotification(Context c, int content) {
    Notification n = GetNotification(c, content);

    //Post the notification.
    NotificationManagerCompat.from(c).notify(NotificationConstants.NOTIFICATION_ID, n);
}

From source file:com.example.android.wearable.wear.wearnotifications.handlers.BigTextIntentService.java

/**
 * Handles action Dismiss in the provided background thread.
 *///from  w w w. j  a va2s. c  o m
private void handleActionDismiss() {
    Log.d(TAG, "handleActionDismiss()");

    NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat
            .from(getApplicationContext());
    notificationManagerCompat.cancel(StandaloneMainActivity.NOTIFICATION_ID);
}