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.master.metehan.filtereagle.ServiceSinkhole.java

private void removeWarningNotifications() {
    NotificationManagerCompat.from(this).cancel(NOTIFY_DISABLED);
    NotificationManagerCompat.from(this).cancel(NOTIFY_ERROR);
}

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

private void showDisabledNotification() {
    Intent main = new Intent(this, MainActivity.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_error_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_revoked)).setContentIntent(pi).setColor(tv.data)
            .setOngoing(false).setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
    }//from  w  w w . j a v a  2 s  .co  m

    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(getString(R.string.msg_revoked));

    NotificationManagerCompat.from(this).notify(NOTIFY_DISABLED, notification.build());
}

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

private void showAutoStartNotification() {
    Intent main = new Intent(this, MainActivity.class);
    main.putExtra(MainActivity.EXTRA_APPROVE, true);
    PendingIntent pi = PendingIntent.getActivity(this, NOTIFY_AUTOSTART, main,
            PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_error_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_autostart)).setContentIntent(pi).setColor(tv.data)
            .setOngoing(false).setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
    }//from w ww  . j  a  va 2s . c o m

    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(getString(R.string.msg_autostart));

    NotificationManagerCompat.from(this).notify(NOTIFY_AUTOSTART, notification.build());
}

From source file:com.linkbubble.ui.ContentView.java

private void configureArticleModeButton() {
    ArticleContent articleContent = mWebRenderer.getArticleContent();
    if (articleContent != null) {
        if (mArticleNotificationId == -1 && TextUtils.isEmpty(articleContent.mText) == false
                && Settings.get().getArticleModeOnWearEnabled()) {
            mArticleNotificationId = sNextArticleNotificationId;
            sNextArticleNotificationId++;

            String title = MainApplication.sTitleHashMap != null
                    ? MainApplication.sTitleHashMap.get(articleContent.mUrl.toString())
                    : "Open Bubble";

            Context context = getContext();

            Intent closeTabIntent = new Intent(context, NotificationCloseTabActivity.class);
            closeTabIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            closeTabIntent.putExtra(NotificationCloseTabActivity.EXTRA_DISMISS_NOTIFICATION,
                    mArticleNotificationId);
            PendingIntent closeTabPendingIntent = PendingIntent.getActivity(context, mArticleNotificationId,
                    closeTabIntent, PendingIntent.FLAG_UPDATE_CURRENT);

            Intent openTabIntent = new Intent(context, NotificationOpenTabActivity.class);
            openTabIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
                    | Intent.FLAG_ACTIVITY_NEW_TASK);
            openTabIntent.putExtra(NotificationOpenTabActivity.EXTRA_DISMISS_NOTIFICATION,
                    mArticleNotificationId);
            PendingIntent openTabPendingIntent = PendingIntent.getActivity(context,
                    (int) System.currentTimeMillis(), openTabIntent, PendingIntent.FLAG_UPDATE_CURRENT);

            Notification notification = new NotificationCompat.Builder(context)
                    .addAction(R.drawable.ic_action_cancel_white, context.getString(R.string.action_close_tab),
                            closeTabPendingIntent)
                    .setContentTitle(title).setContentText(articleContent.mText)
                    .setSmallIcon(R.drawable.ic_launcher).setGroup(Constant.NOTIFICATION_GROUP_KEY_ARTICLES)
                    .setContentIntent(openTabPendingIntent).build();

            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
            notificationManager.notify(mArticleNotificationId, notification);
        }//  w  w w. j  av a 2  s . c  o  m

        if (Settings.get().getArticleModeEnabled()) {
            mArticleModeButton.setVisibility(VISIBLE);
        } else {
            mArticleModeButton.setVisibility(GONE);
        }
    } else {
        mArticleModeButton.setVisibility(GONE);
        if (mArticleRenderer != null) {
            mArticleRenderer.stopLoading();
        }
        cancelWearNotification();
    }
}

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

private void showErrorNotification(String message) {
    Intent main = new Intent(this, MainActivity.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_error_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_error, message)).setContentIntent(pi).setColor(tv.data)
            .setOngoing(false).setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
    }//w  w  w.  j  a v a 2s.c  o m

    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(getString(R.string.msg_error, message));
    notification.setSummaryText(message);

    NotificationManagerCompat.from(this).notify(NOTIFY_ERROR, notification.build());
}

From source file:com.linkbubble.ui.ContentView.java

private void cancelWearNotification() {
    if (mArticleNotificationId > -1) {
        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getContext());
        notificationManager.cancel(mArticleNotificationId);
        mArticleNotificationId = -1;/* w w  w  .  j  av a  2  s.  co m*/
    }
}

From source file:com.zhengde163.netguard.ServiceSinkhole.java

private void showUpdateNotification(String name, String url) {
    Intent download;//www  .j a  v  a  2s . c om
    File tmpFile = new File(Environment.getExternalStorageDirectory(), fileName);

    String status;
    if (!tmpFile.exists()) {
        status = getString(R.string.msg_update);
        download = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    } else {
        int size = 0;
        try {
            FileInputStream in = new FileInputStream(tmpFile);
            size = in.available();
            in.close();
        } catch (Exception e) {
            // Do nothing.
        }
        if (size > 2000000) {
            status = "?, ";
            download = new Intent(Intent.ACTION_VIEW);
            download.setDataAndType(Uri.fromFile(tmpFile), "application/vnd.android.package-archive");
        } else {
            return;
        }
    }
    PendingIntent pi = PendingIntent.getActivity(this, 0, download, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_security_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(status).setContentIntent(pi).setColor(tv.data).setOngoing(false)
            .setAutoCancel(true);

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

    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(getString(R.string.msg_update));
    notification.setSummaryText(name);

    NotificationManagerCompat.from(this).notify(NOTIFY_UPDATE, notification.build());
}

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

private void showAccessNotification(int uid) {
    String name = TextUtils.join(", ", Util.getApplicationNames(uid, ServiceSinkhole.this));

    Intent main = new Intent(ServiceSinkhole.this, MainActivity.class);
    main.putExtra(MainActivity.EXTRA_SEARCH, Integer.toString(uid));
    PendingIntent pi = PendingIntent.getActivity(ServiceSinkhole.this, uid + 10000, main,
            PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOn, tv, true);
    int colorOn = tv.data;
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    int colorOff = tv.data;

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_cloud_upload_white_24dp).setGroup("AccessAttempt").setContentIntent(pi)
            .setColor(colorOff).setOngoing(false).setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        builder.setContentTitle(name).setContentText(getString(R.string.msg_access_n));
    else//w  w w.j  ava  2s.com
        builder.setContentTitle(getString(R.string.app_name))
                .setContentText(getString(R.string.msg_access, name));

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

    DateFormat df = new SimpleDateFormat("dd HH:mm");

    NotificationCompat.InboxStyle notification = new NotificationCompat.InboxStyle(builder);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        notification.addLine(getString(R.string.msg_access_n));
    else {
        String sname = getString(R.string.msg_access, name);
        int pos = sname.indexOf(name);
        Spannable sp = new SpannableString(sname);
        sp.setSpan(new StyleSpan(Typeface.BOLD), pos, pos + name.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        notification.addLine(sp);
    }

    Cursor cursor = DatabaseHelper.getInstance(ServiceSinkhole.this).getAccessUnset(uid, 7);
    int colDAddr = cursor.getColumnIndex("daddr");
    int colTime = cursor.getColumnIndex("time");
    int colAllowed = cursor.getColumnIndex("allowed");
    while (cursor.moveToNext()) {
        StringBuilder sb = new StringBuilder();
        sb.append(df.format(cursor.getLong(colTime))).append(' ');

        String daddr = cursor.getString(colDAddr);
        if (Util.isNumericAddress(daddr))
            try {
                daddr = InetAddress.getByName(daddr).getHostName();
            } catch (UnknownHostException ignored) {
            }
        sb.append(daddr);

        int allowed = cursor.getInt(colAllowed);
        if (allowed >= 0) {
            int pos = sb.indexOf(daddr);
            Spannable sp = new SpannableString(sb);
            ForegroundColorSpan fgsp = new ForegroundColorSpan(allowed > 0 ? colorOn : colorOff);
            sp.setSpan(fgsp, pos, pos + daddr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            notification.addLine(sp);
        } else
            notification.addLine(sb);
    }
    cursor.close();

    NotificationManagerCompat.from(this).notify(uid + 10000, notification.build());
}

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

private void showUpdateNotification(String name, String url) {
    Intent download = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    PendingIntent pi = PendingIntent.getActivity(this, 0, download, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_security_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_update)).setContentIntent(pi).setColor(tv.data)
            .setOngoing(false).setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
    }/*from w  ww . ja  v a 2s. c o  m*/

    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(getString(R.string.msg_update));
    notification.setSummaryText(name);

    NotificationManagerCompat.from(this).notify(NOTIFY_UPDATE, notification.build());
}

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

private void removeWarningNotifications() {
    NotificationManagerCompat.from(this).cancel(NOTIFY_DISABLED);
    NotificationManagerCompat.from(this).cancel(NOTIFY_AUTOSTART);
    NotificationManagerCompat.from(this).cancel(NOTIFY_ERROR);
}