Example usage for android.app Notification FLAG_LOCAL_ONLY

List of usage examples for android.app Notification FLAG_LOCAL_ONLY

Introduction

In this page you can find the example usage for android.app Notification FLAG_LOCAL_ONLY.

Prototype

int FLAG_LOCAL_ONLY

To view the source code for android.app Notification FLAG_LOCAL_ONLY.

Click Source Link

Document

Bit to be bitswise-ored into the #flags field that should be set if this notification is relevant to the current device only and it is not recommended that it bridge to other devices.

Usage

From source file:com.oasisfeng.nevo.decorators.bundle.BundleDecorator.java

private void bundle(final StatusBarNotificationEvo evolving, final String bundle) {
    Log.i(TAG, "Bundle " + evolving.getKey() + " into " + bundle);
    try {//from   w w w . j av a2  s  .  c  o  m
        mBundles.setNotificationBundle(evolving.getKey(), bundle);
        if (!showBundleNotificationIfNeeded(bundle))
            return;

        final IBundle extras = evolving.notification().extras();
        if ((evolving.notification().getFlags() & Notification.FLAG_LOCAL_ONLY) != 0) {
            extras.putBoolean(NevoConstants.EXTRA_REMOVED, true);
            return;
        }
        extras.putBoolean(NotificationManagerCompat.EXTRA_USE_SIDE_CHANNEL, true);
        extras.putString("android.support.groupKey", bundle);
    } catch (final RemoteException ignored) {
    } // Should never happen
}

From source file:org.kde.kdeconnect.Plugins.NotificationsPlugin.NotificationsPlugin.java

public void sendNotification(StatusBarNotification statusBarNotification, boolean requestAnswer) {

    Notification notification = statusBarNotification.getNotification();
    AppDatabase appDatabase = new AppDatabase(context);

    if ((notification.flags & Notification.FLAG_FOREGROUND_SERVICE) != 0
            || (notification.flags & Notification.FLAG_ONGOING_EVENT) != 0
            || (notification.flags & Notification.FLAG_LOCAL_ONLY) != 0) {
        //This is not a notification we want!
        return;/* w  w  w . j  av a2s  . c o m*/
    }

    appDatabase.open();
    if (!appDatabase.isEnabled(statusBarNotification.getPackageName())) {
        return;
        // we dont want notification from this app
    }
    appDatabase.close();

    String key = getNotificationKeyCompat(statusBarNotification);
    String packageName = statusBarNotification.getPackageName();
    String appName = AppsHelper.appNameLookup(context, packageName);

    if ("com.facebook.orca".equals(packageName) && (statusBarNotification.getId() == 10012)
            && "Messenger".equals(appName) && notification.tickerText == null) {
        //HACK: Hide weird Facebook empty "Messenger" notification that is actually not shown in the phone
        return;
    }

    if (packageName.equals("com.google.android.googlequicksearchbox")) {
        //HACK: Hide Google Now notifications that keep constantly popping up (and without text because we don't know how to read them properly)
        return;
    }

    NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_NOTIFICATION);

    if (packageName.equals("org.kde.kdeconnect_tp")) {
        //Make our own notifications silent :)
        np.set("silent", true);
        np.set("requestAnswer", true); //For compatibility with old desktop versions of KDE Connect that don't support "silent"
    }
    /*
            if (sendIcons) {
    try {
        Drawable drawableAppIcon = AppsHelper.appIconLookup(context, packageName);
        Bitmap appIcon = ImagesHelper.drawableToBitmap(drawableAppIcon);
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        if (appIcon.getWidth() > 128) {
            appIcon = Bitmap.createScaledBitmap(appIcon, 96, 96, true);
        }
        appIcon.compress(Bitmap.CompressFormat.PNG, 90, outStream);
        byte[] bitmapData = outStream.toByteArray();
        np.setPayload(bitmapData);
    } catch (Exception e) {
        e.printStackTrace();
        Log.e("NotificationsPlugin", "Error retrieving icon");
    }
            }
    */
    np.set("id", key);
    np.set("appName", appName == null ? packageName : appName);
    np.set("isClearable", statusBarNotification.isClearable());
    np.set("ticker", getTickerText(notification));
    np.set("time", Long.toString(statusBarNotification.getPostTime()));
    if (requestAnswer) {
        np.set("requestAnswer", true);
        np.set("silent", true);
    }

    device.sendPackage(np);
}

From source file:pylapp.smoothclicker.android.notifiers.StatusBarNotifier.java

/**
 * Makes a unmovable notification with a dedicated LED color.
 * This notification is an "on going" one, and should be displayed will the app is clicking.
 *
 * @param type - The notification type/* w w w  .ja  v  a  2  s. co m*/
 * @param params -
 *               <ul>
 *                  <li>For CLICK_MADE :params[0] for the X coordinate, params[1] for the Y coordinate</li>
 *                  <li>For COUNT_DOWN :params[0] for the leaving time to display</li>
 *                  <li>Nothing otherwise</li>
 *               </ul>
 */
public void makeNotification(NotificationTypes type, long... params) {

    Logger.d(LOG_TAG, "New notification: " + type);

    NotificationCompat.Builder b = new NotificationCompat.Builder(mContext);
    b.setSmallIcon(R.drawable.notification_icon);
    b.setContentTitle(mContext.getString(R.string.notif_content_title));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        b.setVisibility(Notification.VISIBILITY_PUBLIC);

    if (type != NotificationTypes.CLICK_MADE && type != NotificationTypes.CLICKS_ON_GOING_BY_SERVICE) {
        Intent activityToStartOnClick = new Intent(mContext, ClickerActivity.class);
        activityToStartOnClick.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent pi = PendingIntent.getActivity(mContext, 0, activityToStartOnClick, 0);
        b.setContentIntent(pi);
    }

    NotificationManager nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification n = null;

    switch (type) {
    case CLICKS_ON_GOING_BY_APP:
        b.setContentText(mContext.getString(R.string.notif_content_text_clicks_on_going_app));
        b.setProgress(0, 0, true);
        b.setLights(0xff9c27b0, 1000, 500);
        n = b.build();
        n.flags |= Notification.FLAG_NO_CLEAR;
        n.flags |= Notification.FLAG_SHOW_LIGHTS;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH)
            n.flags |= Notification.FLAG_LOCAL_ONLY;
        nm.notify(NOTIF_CLICK_PROCESS_ON_GOING_BY_APP, n);
        break;
    case CLICKS_ON_GOING_STANDALONE:
        b.setContentText(mContext.getString(R.string.notif_content_text_clicks_on_going_standalone));
        b.setProgress(0, 0, true);
        b.setLights(0xff9c27b0, 1000, 500);
        n = b.build();
        n.flags |= Notification.FLAG_NO_CLEAR;
        n.flags |= Notification.FLAG_SHOW_LIGHTS;
        n.flags |= Notification.FLAG_LOCAL_ONLY;
        nm.notify(NOTIF_CLICK_PROCESS_ON_GOING_STANDALONE, n);
        break;
    case CLICKS_ON_GOING_BY_SERVICE:
        b.setContentText(mContext.getString(R.string.notif_content_text_clicks_on_going_service));
        b.setProgress(0, 0, true);
        b.setLights(0xff9c27b0, 1000, 500);
        n = b.build();
        n.flags |= Notification.FLAG_NO_CLEAR;
        n.flags |= Notification.FLAG_SHOW_LIGHTS;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH)
            n.flags |= Notification.FLAG_LOCAL_ONLY;
        nm.notify(NOTIF_CLICK_PROCESS_ON_GOING_BY_SERVICE, n);
        break;
    case CLICKS_STOPPED:
        b.setContentText(mContext.getString(R.string.notif_content_text_clicks_stop));
        n = b.build();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH)
            n.flags |= Notification.FLAG_LOCAL_ONLY;
        nm.notify(NOTIF_CLICK_PROCESS_STOPPED, n);
        break;
    case CLICKS_OVER:
        b.setContentText(mContext.getString(R.string.notif_content_text_clicks_over));
        n = b.build();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH)
            n.flags |= Notification.FLAG_LOCAL_ONLY;
        nm.notify(NOTIF_CLICK_PROCESS_OVER, n);
        break;
    case WATCH_OVER:
        b.setContentText(mContext.getString(R.string.notif_content_text_watch_over));
        n = b.build();
        n.flags |= Notification.FLAG_LOCAL_ONLY;
        nm.notify(NOTIF_WATCH_PROCESS_OVER, n);
        break;
    case CLICK_MADE:
        StringBuilder sb = new StringBuilder();
        sb.append(mContext.getString(R.string.notif_content_text_click_made));
        if (params != null && params.length == 2) {
            sb.append(" : ").append(params[0]).append(" / ").append(params[1]);
        }
        b.setContentText(sb.toString());
        n = b.build();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH)
            n.flags |= Notification.FLAG_LOCAL_ONLY;
        nm.notify(NOTIF_CLICK_MADE, n);
        break;
    case SU_GRANTED:
        b.setContentText(mContext.getString(R.string.notif_content_text_su_granted));
        n = b.build();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH)
            n.flags |= Notification.FLAG_LOCAL_ONLY;
        nm.notify(NOTIF_SU_GRANTED, n);
        break;
    case COUNT_DOWN:
        if (params != null && params.length == 1) {
            b.setContentText(mContext.getString(R.string.notif_content_text_countdown) + " " + params[0]);
        } else {
            b.setContentText(mContext.getString(R.string.notif_content_text_countdown));
        }
        n = b.build();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH)
            n.flags |= Notification.FLAG_NO_CLEAR;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH)
            n.flags |= Notification.FLAG_LOCAL_ONLY;
        nm.notify(NOTIF_COUNT_DOWN, n);
        break;
    }

}

From source file:com.bluelinelabs.logansquare.typeconverters.NotificationConverter.java

@TargetApi(Build.VERSION_CODES.KITKAT)
@NonNull//from ww w.  ja v a2s  . com
public static SimpleNotification toSimpleNotification(@NonNull Notification notification) {
    SimpleNotification simpleNotification = new SimpleNotification();

    simpleNotification.autoCancel = (notification.flags
            & Notification.FLAG_AUTO_CANCEL) == Notification.FLAG_AUTO_CANCEL;
    android.util.Log.d("json2notification", "autoCancel:" + simpleNotification.autoCancel);

    //simpleNotification.bigPictureStyle // TODO

    simpleNotification.category = notification.category;
    simpleNotification.color = notification.color > 0 ? notification.color : null;
    simpleNotification.contentInfo = notification.extras.getString(Notification.EXTRA_INFO_TEXT);
    simpleNotification.contentIntent = notification.contentIntent;
    simpleNotification.contentTitle = notification.extras.getString(Notification.EXTRA_TITLE);
    simpleNotification.contentText = notification.extras.getString(Notification.EXTRA_TEXT);
    simpleNotification.defaults = notification.defaults > 0 ? notification.defaults : null;
    simpleNotification.deleteIntent = notification.deleteIntent;
    //simpleNotification.extras;
    simpleNotification.groupKey = notification.getGroup();
    if (simpleNotification.groupKey != null) {
        simpleNotification.groupSummary = (notification.flags
                & Notification.FLAG_GROUP_SUMMARY) == Notification.FLAG_GROUP_SUMMARY;
    }
    Bitmap bitmap = notification.extras.getParcelable(Notification.EXTRA_LARGE_ICON);
    if (bitmap != null)
        simpleNotification.largeIcon = Bitmaps.base64(bitmap);
    if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) == Notification.FLAG_SHOW_LIGHTS) {
        simpleNotification.lights = Arrays.asList(notification.ledARGB, notification.ledOnMS,
                notification.ledOffMS);
    }
    simpleNotification.localOnly = (notification.flags
            & Notification.FLAG_LOCAL_ONLY) == Notification.FLAG_LOCAL_ONLY;
    simpleNotification.number = notification.number > 0 ? notification.number : null;
    simpleNotification.ongoing = (notification.flags
            & Notification.FLAG_ONGOING_EVENT) == Notification.FLAG_ONGOING_EVENT;
    simpleNotification.onlyAlertOnce = (notification.flags
            & Notification.FLAG_ONLY_ALERT_ONCE) == Notification.FLAG_ONLY_ALERT_ONCE;
    String[] people = notification.extras.getStringArray(Notification.EXTRA_PEOPLE);
    if (people != null) {
        simpleNotification.people = Arrays.asList(people);
    }
    simpleNotification.priority = notification.priority > 0 ? notification.priority : null;
    //simpleNotification.progress;
    simpleNotification.publicVersion = notification.publicVersion;
    simpleNotification.showWhen = notification.extras.getBoolean(Notification.EXTRA_SHOW_WHEN);
    if (simpleNotification.showWhen) {
        simpleNotification.when = notification.when;
    }
    simpleNotification.smallIcon = String.valueOf(notification.extras.getInt(Notification.EXTRA_SMALL_ICON)); // TODO getResourceNameById()
    android.util.Log.d("json2notification", "simpleNotification.smallIcon" + simpleNotification.smallIcon);
    simpleNotification.sortKey = notification.getSortKey();
    simpleNotification.sound = notification.sound;
    simpleNotification.subText = notification.extras.getString(Notification.EXTRA_SUB_TEXT);
    simpleNotification.tickerText = notification.tickerText;
    simpleNotification.usesChronometer = notification.extras.getBoolean(Notification.EXTRA_SHOW_CHRONOMETER);
    simpleNotification.visibility = notification.visibility > 0 ? notification.visibility : null;
    return simpleNotification;
}

From source file:com.zertinteractive.wallpaper.MainActivity.java

@SuppressLint("NewApi")
public void setNotification() {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager notificationManager = (NotificationManager) getSystemService(ns);

    @SuppressWarnings("deprecation")
    Notification notification = new Notification(R.drawable.ic_launcher, "Ticker Text",
            System.currentTimeMillis());

    RemoteViews notificationView = new RemoteViews(getPackageName(), R.layout.romantic_wallpaper);

    //the intent that is started when the notification is clicked (works)
    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    notification.contentView = notificationView;
    notification.contentIntent = pendingNotificationIntent;
    //        notification.flags |= Notification.FLAG_NO_CLEAR;
    notification.flags = Notification.FLAG_LOCAL_ONLY;

    //this is the intent that is supposed to be called when the button is clicked
    Intent switchIntent = new Intent(this, MainActivity.class);
    PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(this, 0, switchIntent, 0);
    ///*from  w  ww.j a va  2s.  c om*/
    notificationView.setOnClickPendingIntent(R.id.download_notification, pendingSwitchIntent);
    notificationManager.notify(1, notification);
}