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.wizardsofm.deskclock.alarms.AlarmNotifications.java

public static void updateAlarmGroupNotification(Context context) {
    if (!Utils.isNOrLater()) {
        return;/*from www . ja  v  a2 s.  c  o  m*/
    }

    NotificationManagerCompat nm = NotificationManagerCompat.from(context);

    if (getActiveNotificationsCount(context, UPCOMING_GROUP_KEY) == 0) {
        nm.cancel(ALARM_GROUP_NOTIFICATION_ID);
        return;
    }

    NotificationCompat.Builder summaryNotification = new NotificationCompat.Builder(context).setShowWhen(false)
            .setColor(ContextCompat.getColor(context, com.wizardsofm.deskclock.R.color.default_background))
            .setSmallIcon(com.wizardsofm.deskclock.R.drawable.stat_notify_alarm).setGroup(UPCOMING_GROUP_KEY)
            .setGroupSummary(true).setPriority(NotificationCompat.PRIORITY_HIGH)
            .setCategory(NotificationCompat.CATEGORY_ALARM).setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setLocalOnly(true);

    nm.notify(ALARM_GROUP_NOTIFICATION_ID, summaryNotification.build());
}

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

private void showEmergencyNotification(String caseId) {
    PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0,
            ConfirmHelpingActivity.generateIntent(this, caseId), PendingIntent.FLAG_UPDATE_CURRENT);
    Notification notification = new NotificationCompat.Builder(getApplicationContext()).setContentTitle("Sigap")
            .setContentText("Seseorang membutuhkan bantuan mu!!!").setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
            .setVibrate(CacheManager.pluck().isVibrate() ? new long[] { 100, 300, 500, 1000 } : new long[] {})
            .setSound(Uri.parse(CacheManager.pluck().getRingtone())).setAutoCancel(true)
            .setStyle(new android.support.v4.app.NotificationCompat.BigTextStyle()
                    .bigText("Seseorang membutuhkan bantuan mu!!!, Ayo segera bantu dia!"))
            .setContentIntent(pendingIntent).build();

    NotificationManagerCompat.from(SigapApp.pluck().getApplicationContext())
            .notify(BenihUtils.randInt(1, Integer.MAX_VALUE), notification);
}

From source file:cz.maresmar.sfm.utils.MenuUtils.java

/**
 * Check if credit is different from previous credit. If so it shows notification (if enabled)
 *
 * @param context        Some valid context
 * @param portalId       ID of portal with corresponding credential
 * @param credentialId   ID of credential to be checked
 * @param previousCredit Previous credit (before some plugin operation like sync happen)
 * @return {@code true} if credit changed, {@code false} otherwise
 *//*from  ww w.  j  a  va  2  s  . c om*/
public static boolean checkCreditChanges(@NonNull Context context, long portalId, long credentialId,
        int previousCredit) {
    try (Cursor cursor = context.getContentResolver().query(
            ProviderContract.LogData.getUri(portalId, credentialId),
            new String[] { ProviderContract.LogData.CREDIT, ProviderContract.LogData.CREDENTIAL_NAME,
                    ProviderContract.Credentials.FLAGS, ProviderContract.Credentials.LOW_CREDIT_THRESHOLD },
            null, null, null)) {

        if (BuildConfig.DEBUG) {
            Assert.isOne(cursor.getCount());
        }

        cursor.moveToFirst();
        int actualCredit = cursor.getInt(0);
        String credentialName = cursor.getString(1);
        @ProviderContract.CredentialFlags
        int flags = cursor.getInt(2);
        int lowCreditThreshold = cursor.getInt(3) * 100;

        boolean increaseNotification = (flags
                & CREDENTIAL_FLAG_DISABLE_CREDIT_INCREASE_NOTIFICATION) != CREDENTIAL_FLAG_DISABLE_CREDIT_INCREASE_NOTIFICATION;
        boolean lowCreditNotification = (flags
                & CREDENTIAL_FLAG_DISABLE_LOW_CREDIT_NOTIFICATION) != CREDENTIAL_FLAG_DISABLE_LOW_CREDIT_NOTIFICATION;

        boolean changed = !(increaseNotification || lowCreditNotification);

        // Credit increased notification
        if (actualCredit > previousCredit && increaseNotification && actualCredit != ProviderContract.NO_INFO) {
            changed = true;

            // Prepare intent
            PendingIntent pendingIntent = MainActivity.getShowCreditIntent(context);

            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context,
                    NotificationContract.CREDIT_CHANGE_CHANNEL_ID).setSmallIcon(R.drawable.notification_icon)
                            .setColor(ContextCompat.getColor(context, R.color.colorPrimary))
                            .setContentTitle(context.getString(R.string.notification_credit_icrease_title))
                            .setContentText(context.getString(R.string.notification_credit_icrease_text,
                                    getPriceStr(context, actualCredit), credentialName))
                            .setPriority(NotificationCompat.PRIORITY_DEFAULT)
                            // Set the intent that will fire when the user taps the notification
                            .setContentIntent(pendingIntent).setAutoCancel(true);

            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
            // notificationId is a unique int for each notification that you must define
            notificationManager.notify((int) credentialId * 10, mBuilder.build());
        }

        if (lowCreditThreshold > actualCredit && lowCreditNotification
                && actualCredit != ProviderContract.NO_INFO) {
            changed = true;

            // Prepare intent
            PendingIntent pendingIntent = MainActivity.getShowCreditIntent(context);

            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context,
                    NotificationContract.CREDIT_CHANGE_CHANNEL_ID).setSmallIcon(R.drawable.notification_icon)
                            .setColor(ContextCompat.getColor(context, R.color.colorPrimary))
                            .setContentTitle(context.getString(R.string.notification_low_credit_title))
                            .setContentText(context.getString(R.string.notification_low_credit_text,
                                    getPriceStr(context, actualCredit), credentialName))
                            .setPriority(NotificationCompat.PRIORITY_DEFAULT)
                            // Set the intent that will fire when the user taps the notification
                            .setContentIntent(pendingIntent).setAutoCancel(true);

            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
            // notificationId is a unique int for each notification that you must define
            notificationManager.notify((int) credentialId * 10, mBuilder.build());
        }

        return changed;
    }
}

From source file:com.piggeh.palmettoscholars.services.MyFirebaseMessagingService.java

public void notifyAnnouncement(String announcement) {
    Intent contentIntent = new Intent(this, MainActivity.class);
    contentIntent.putExtra("navigation_page", MainActivity.PAGE_ANNOUNCEMENTS);
    contentIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentPendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, contentIntent,
            PendingIntent.FLAG_ONE_SHOT);

    Intent settingsIntent = new Intent(this, SettingsActivity.class);
    settingsIntent.putExtra("navigation_page", MainActivity.PAGE_SETTINGS);
    settingsIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent settingsPendingIntent = PendingIntent.getActivity(this, 1 /* Request code */, settingsIntent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.BigTextStyle notifStyle = new NotificationCompat.BigTextStyle();
    notifStyle.bigText(announcement);//w ww.j  av a2 s  .  c  om
    notifStyle.setBigContentTitle(getString(R.string.notif_announcement_title));

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.notification_icon_nodpi)
            .setContentTitle(getString(R.string.notif_announcement_title)).setContentText(announcement)
            .setAutoCancel(true).setSound(defaultSoundUri)
            .setColor(ContextCompat.getColor(this, R.color.colorPrimary)).setContentIntent(contentPendingIntent)
            .setStyle(notifStyle).addAction(R.drawable.ic_notifications_off,
                    getString(R.string.notif_action_options), settingsPendingIntent);

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

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

From source file:com.perfilyev.vkmessengerlite.MessagingService.java

private void doNotify(String notificationTag, Notification notification) {
    NotificationManagerCompat.from(this).notify(notificationTag, NOTIFICATION_ID, notification);
}

From source file:eu.faircode.netguard.Receiver.java

public static void notifyNewApplication(int uid, Context context) {
    if (uid < 0)
        return;//  ww  w. j  a  va2 s . c o  m

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    try {
        // Get application info
        String name = TextUtils.join(", ", Util.getApplicationNames(uid, context));

        // Get application info
        PackageManager pm = context.getPackageManager();
        String[] packages = pm.getPackagesForUid(uid);
        if (packages == null || packages.length < 1)
            throw new PackageManager.NameNotFoundException(Integer.toString(uid));
        boolean internet = Util.hasInternet(uid, context);

        // Build notification
        Intent main = new Intent(context, ActivityMain.class);
        main.putExtra(ActivityMain.EXTRA_REFRESH, true);
        main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid));
        PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT);

        Util.setTheme(context);
        TypedValue tv = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_security_white_24dp).setContentIntent(pi).setColor(tv.data)
                .setAutoCancel(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
            builder.setContentTitle(name).setContentText(context.getString(R.string.msg_installed_n));
        else
            builder.setContentTitle(context.getString(R.string.app_name))
                    .setContentText(context.getString(R.string.msg_installed, name));

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
        }

        // Get defaults
        SharedPreferences prefs_wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE);
        SharedPreferences prefs_other = context.getSharedPreferences("other", Context.MODE_PRIVATE);
        boolean wifi = prefs_wifi.getBoolean(packages[0], prefs.getBoolean("whitelist_wifi", true));
        boolean other = prefs_other.getBoolean(packages[0], prefs.getBoolean("whitelist_other", true));

        // Build Wi-Fi action
        Intent riWifi = new Intent(context, ServiceSinkhole.class);
        riWifi.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riWifi.putExtra(ServiceSinkhole.EXTRA_NETWORK, "wifi");
        riWifi.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riWifi.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !wifi);

        PendingIntent piWifi = PendingIntent.getService(context, uid, riWifi,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(wifi ? R.drawable.wifi_on : R.drawable.wifi_off,
                context.getString(wifi ? R.string.title_allow : R.string.title_block), piWifi);

        // Build mobile action
        Intent riOther = new Intent(context, ServiceSinkhole.class);
        riOther.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riOther.putExtra(ServiceSinkhole.EXTRA_NETWORK, "other");
        riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riOther.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !other);
        PendingIntent piOther = PendingIntent.getService(context, uid + 10000, riOther,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(other ? R.drawable.other_on : R.drawable.other_off,
                context.getString(other ? R.string.title_allow : R.string.title_block), piOther);

        // Show notification
        if (internet)
            NotificationManagerCompat.from(context).notify(uid, builder.build());
        else {
            NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                expanded.bigText(context.getString(R.string.msg_installed_n));
            else
                expanded.bigText(context.getString(R.string.msg_installed, name));
            expanded.setSummaryText(context.getString(R.string.title_internet));
            NotificationManagerCompat.from(context).notify(uid, expanded.build());
        }

    } catch (PackageManager.NameNotFoundException ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
}

From source file:android_network.hetnet.vpn_service.Receiver.java

public static void notifyNewApplication(int uid, Context context) {
    if (uid < 0)
        return;//w  w w  . jav  a  2s  .  c o m

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    try {
        // Get application info
        String name = TextUtils.join(", ", Util.getApplicationNames(uid, context));

        // Get application info
        PackageManager pm = context.getPackageManager();
        String[] packages = pm.getPackagesForUid(uid);
        if (packages == null || packages.length < 1)
            throw new PackageManager.NameNotFoundException(Integer.toString(uid));
        boolean internet = Util.hasInternet(uid, context);

        // Build notification
        Intent main = new Intent(context, MainActivity.class);
        main.putExtra(MainActivity.EXTRA_REFRESH, true);
        main.putExtra(MainActivity.EXTRA_SEARCH, Integer.toString(uid));
        PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT);

        Util.setTheme(context);
        TypedValue tv = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_security_white_24dp).setContentIntent(pi).setColor(tv.data)
                .setAutoCancel(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
            builder.setContentTitle(name).setContentText(context.getString(R.string.msg_installed_n));
        else
            builder.setContentTitle(context.getString(R.string.app_name))
                    .setContentText(context.getString(R.string.msg_installed, name));

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
        }

        // Get defaults
        SharedPreferences prefs_wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE);
        SharedPreferences prefs_other = context.getSharedPreferences("other", Context.MODE_PRIVATE);
        boolean wifi = prefs_wifi.getBoolean(packages[0], prefs.getBoolean("whitelist_wifi", true));
        boolean other = prefs_other.getBoolean(packages[0], prefs.getBoolean("whitelist_other", true));

        // Build Wi-Fi action
        Intent riWifi = new Intent(context, ServiceSinkhole.class);
        riWifi.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riWifi.putExtra(ServiceSinkhole.EXTRA_NETWORK, "wifi");
        riWifi.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riWifi.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !wifi);

        PendingIntent piWifi = PendingIntent.getService(context, uid, riWifi,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(wifi ? R.drawable.wifi_on : R.drawable.wifi_off,
                context.getString(wifi ? R.string.title_allow : R.string.title_block), piWifi);

        // Build mobile action
        Intent riOther = new Intent(context, ServiceSinkhole.class);
        riOther.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riOther.putExtra(ServiceSinkhole.EXTRA_NETWORK, "other");
        riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riOther.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !other);
        PendingIntent piOther = PendingIntent.getService(context, uid + 10000, riOther,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(other ? R.drawable.other_on : R.drawable.other_off,
                context.getString(other ? R.string.title_allow : R.string.title_block), piOther);

        // Show notification
        if (internet)
            NotificationManagerCompat.from(context).notify(uid, builder.build());
        else {
            NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                expanded.bigText(context.getString(R.string.msg_installed_n));
            else
                expanded.bigText(context.getString(R.string.msg_installed, name));
            expanded.setSummaryText(context.getString(R.string.title_internet));
            NotificationManagerCompat.from(context).notify(uid, expanded.build());
        }

    } catch (PackageManager.NameNotFoundException ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
}

From source file:com.dotcom.jamaat.fcm.GCMListenerService.java

public void setNotificationSound() {
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    mBuilder.setSound(defaultSoundUri);/*from w  ww. j a v a  2  s.c om*/
    //    mBuilder.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 });
    NotificationManagerCompat notificationManager1 = NotificationManagerCompat.from(this);
    notificationManager1.notify(1, mBuilder.build());
}

From source file:eu.faircode.adblocker.Receiver.java

public static void notifyNewApplication(int uid, Context context) {
    if (uid < 0)
        return;/*  w  ww  .  j  a  va  2 s . c  o  m*/

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    try {
        // Get application info
        String name = TextUtils.join(", ", Util.getApplicationNames(uid, context));

        // Get application info
        PackageManager pm = context.getPackageManager();
        String[] packages = pm.getPackagesForUid(uid);
        if (packages.length < 1)
            throw new PackageManager.NameNotFoundException(Integer.toString(uid));
        boolean internet = Util.hasInternet(uid, context);

        // Build notification
        Intent main = new Intent(context, ActivityMain.class);
        main.putExtra(ActivityMain.EXTRA_REFRESH, true);
        main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid));
        PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT);

        Util.setTheme(context);
        TypedValue tv = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_security_white_24dp)
                .setContentTitle(context.getString(R.string.app_name))
                .setContentText(context.getString(R.string.msg_installed, name)).setContentIntent(pi)
                .setColor(tv.data).setAutoCancel(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
        }

        // Get defaults
        SharedPreferences prefs_wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE);
        SharedPreferences prefs_other = context.getSharedPreferences("other", Context.MODE_PRIVATE);
        boolean wifi = prefs_wifi.getBoolean(packages[0], prefs.getBoolean("whitelist_wifi", true));
        boolean other = prefs_other.getBoolean(packages[0], prefs.getBoolean("whitelist_other", true));

        // Build Wi-Fi action
        Intent riWifi = new Intent(context, ServiceSinkhole.class);
        riWifi.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riWifi.putExtra(ServiceSinkhole.EXTRA_NETWORK, "wifi");
        riWifi.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riWifi.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !wifi);

        PendingIntent piWifi = PendingIntent.getService(context, uid, riWifi,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(wifi ? R.drawable.wifi_on : R.drawable.wifi_off,
                context.getString(wifi ? R.string.title_allow : R.string.title_block), piWifi);

        // Build mobile action
        Intent riOther = new Intent(context, ServiceSinkhole.class);
        riOther.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riOther.putExtra(ServiceSinkhole.EXTRA_NETWORK, "other");
        riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riOther.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !other);
        PendingIntent piOther = PendingIntent.getService(context, uid + 10000, riOther,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(other ? R.drawable.other_on : R.drawable.other_off,
                context.getString(other ? R.string.title_allow : R.string.title_block), piOther);

        // Show notification
        if (internet)
            NotificationManagerCompat.from(context).notify(uid, builder.build());
        else {
            NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder);
            expanded.bigText(context.getString(R.string.msg_installed, name));
            expanded.setSummaryText(context.getString(R.string.title_internet));
            NotificationManagerCompat.from(context).notify(uid, expanded.build());
        }

    } catch (PackageManager.NameNotFoundException ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
}

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

public static void showMissedNotification(Context context, AlarmInstance instance) {
    LogUtils.v("Displaying missed notification for alarm instance: " + instance.mId);

    String label = instance.mLabel;
    String alarmTime = AlarmUtils.getFormattedTime(context, instance.getAlarmTime());
    NotificationCompat.Builder notification = new NotificationCompat.Builder(context)
            .setContentTitle(context.getString(R.string.alarm_missed_title))
            .setContentText(instance.mLabel.isEmpty() ? alarmTime
                    : context.getString(R.string.alarm_missed_text, alarmTime, label))
            .setSmallIcon(R.drawable.stat_notify_alarm).setPriority(NotificationCompat.PRIORITY_HIGH)
            .setCategory(NotificationCompat.CATEGORY_ALARM).setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setLocalOnly(true);/*w  ww  .  j  a  va2s.c  o  m*/

    final int hashCode = instance.hashCode();

    // Setup dismiss intent
    Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context,
            AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.DISMISSED_STATE);
    notification.setDeleteIntent(
            PendingIntent.getService(context, hashCode, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    // Setup content intent
    Intent showAndDismiss = AlarmInstance.createIntent(context, AlarmStateManager.class, instance.mId);
    showAndDismiss.putExtra(EXTRA_NOTIFICATION_ID, hashCode);
    showAndDismiss.setAction(AlarmStateManager.SHOW_AND_DISMISS_ALARM_ACTION);
    notification.setContentIntent(
            PendingIntent.getBroadcast(context, hashCode, showAndDismiss, PendingIntent.FLAG_UPDATE_CURRENT));

    NotificationManagerCompat nm = NotificationManagerCompat.from(context);
    nm.notify(hashCode, notification.build());
}