Example usage for android.app Notification EXTRA_TITLE

List of usage examples for android.app Notification EXTRA_TITLE

Introduction

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

Prototype

String EXTRA_TITLE

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

Click Source Link

Document

#extras key: this is the title of the notification, as supplied to Builder#setContentTitle(CharSequence) .

Usage

From source file:gowtham.com.desknote.MyListener.java

@Override
public void onNotificationPosted(StatusBarNotification sbn) {
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);

    // If user has disabled notifications, then skip
    if (!pref.getBoolean("send_notifications", false))
        return;//from w ww  . ja v a 2  s  .co m

    // Look for our device
    Set<String> emptySet = new HashSet<String>();
    Collection<String> addresses = pref.getStringSet("desktop_address", emptySet);
    Log.i(MainActivity.TAG, "Connected devices " + connectedDevices);
    Collection<String> connectedAddresses = getConnectedAddresses(addresses, connectedDevices);

    Notification mNotification = sbn.getNotification();

    // Can't do much if we get a null!
    if (mNotification == null)
        return;

    Bundle extras = mNotification.extras;

    String packageName = sbn.getPackageName();
    String title = extras.getString(Notification.EXTRA_TITLE);
    String text = extras.getString(Notification.EXTRA_TEXT);
    String subText = extras.getString(Notification.EXTRA_SUB_TEXT);
    Integer smallIconID = extras.getInt(Notification.EXTRA_SMALL_ICON);
    String icon = "null";
    if (pref.getBoolean("include_images", false)) {
        if (extras.getParcelable(Notification.EXTRA_LARGE_ICON) != null) {
            Bitmap b = Bitmap.class.cast(extras.getParcelable(Notification.EXTRA_LARGE_ICON));
            icon = bitmap2Base64(b);
        } else {
            icon = getIcon(packageName, smallIconID);
        }
    }

    Map<String, String> extrasMap = new HashMap<String, String>();
    for (String key : extras.keySet()) {
        extrasMap.put(key, String.valueOf(extras.get(key)));
    }

    Log.e(MainActivity.TAG, "Got a new notification " + title + " " + mNotification.hashCode());

    Message msg = new Message(title, text, subText, icon, mNotification.toString(), extrasMap, packageName);
    NotificationTransmitter tx = new NotificationTransmitter();

    Log.e(MainActivity.TAG, "Sending bluetooth message");
    tx.transmit(connectedAddresses, msg);
}

From source file:com.yangtsaosoftware.pebblemessenger.services.NotificationService.java

@Override
public void onNotificationPosted(StatusBarNotification sbn) {
    if (sbn == null)
        return;/*from  w w  w.j a  va 2 s . co  m*/
    Constants.log(LOG_TAG, "New Access Event:" + sbn.getPackageName() + " tag:" + sbn.getTag());
    /*if(event.getEventType()!= AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED){
            
    return;
    }
    */
    PowerManager powMan = (PowerManager) this.getSystemService(POWER_SERVICE);
    if (!notifScreenOn && powMan.isScreenOn()) {
        Constants.log(LOG_TAG, "because screen out!");
        return;
    }
    //Parcelable parcelable=event.getParcelableData();
    //if(!(parcelable instanceof Notification)) return;
    Notification notif = sbn.getNotification();
    if (sbn.isOngoing()) {
        Constants.log(LOG_TAG, "because is Ongoing!");
        return;
    }

    String eventPackageName;

    if (sbn.getPackageName() != null) {
        eventPackageName = sbn.getPackageName();
    } else {
        Constants.log(LOG_TAG, "Can't get event package name. Returning.");
        return;
    }

    boolean found = false;
    for (String packageName : packages) {
        if (packageName.equalsIgnoreCase(eventPackageName)) {
            found = true;
            break;
        }
    }
    if (!found) {
        Constants.log(LOG_TAG, eventPackageName + " was not found in the include list. Returning.");
        return;
    }
    String title = eventPackageName.substring(eventPackageName.lastIndexOf('.') + 1);
    // get the notification text
    Bundle notiBundle = notif.extras;
    StringBuilder notifySb = new StringBuilder();
    CharSequence notifyChars = notiBundle.getCharSequence(Notification.EXTRA_TITLE);
    if (notifyChars != null) {
        notifySb.append(notifyChars);
    } else {
        Constants.log(LOG_TAG, "empty message title,return!");
        return;
    }

    CharSequence bodyCS = notiBundle.getCharSequence(Notification.EXTRA_TEXT);
    if (bodyCS != null) {
        notifySb.append(":");
        notifySb.append(bodyCS);
    } else {
        Constants.log(LOG_TAG, "empty message body,return!" + notifySb.toString());
        return;
    }
    bodyCS = notiBundle.getCharSequence(Notification.EXTRA_SUB_TEXT);
    if (bodyCS != null) {
        notifySb.append(bodyCS);
    }

    Message msg = Message.obtain();
    msg.what = MessageProcessingService.MSG_NEW_MESSAGE;
    Bundle b = new Bundle();
    b.putString(MessageDbHandler.COL_MESSAGE_APP, title);
    b.putString(MessageDbHandler.COL_MESSAGE_CONTENT, notifySb.toString());
    Constants.log(LOG_TAG, "Send new message title:" + title + " body:" + notifySb.toString());
    msg.setData(b);
    try {
        rMessageProcessHandler.send(msg);
    } catch (RemoteException e) {
        e.printStackTrace();
        Constants.log(LOG_TAG, "Error when sending message to MessageProcessingService.");
    }
}

From source file:com.ademsha.appnotifico.NotificationDataHelper.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private static JSONObject getNotificationExtras(JSONObject notification,
        StatusBarNotification statusBarNotification) {
    try {//from ww w.  ja va 2  s. c o  m
        Bundle extras = statusBarNotification.getNotification().extras;
        if (extras != null) {
            notification.put("text", extras.getString(Notification.EXTRA_TEXT));
            notification.put("sub_text", extras.getString(Notification.EXTRA_SUB_TEXT));
            notification.put("summary_text", extras.getString(Notification.EXTRA_SUMMARY_TEXT));
            notification.put("text_lines", Arrays
                    .toString(extras.getCharSequenceArray(Notification.EXTRA_TEXT_LINES)).replace("null", ""));
            notification.put("icon", String.valueOf(extras.getInt(Notification.EXTRA_SMALL_ICON)));
            if (extras.getParcelable(Notification.EXTRA_LARGE_ICON) != null) {
                notification.put("large_icon",
                        String.valueOf(extras.getParcelable(Notification.EXTRA_LARGE_ICON).toString())
                                .replace("null", ""));
            }
            notification.put("title", extras.getString(Notification.EXTRA_TITLE));
            notification.put("title_big", extras.getString(Notification.EXTRA_TITLE_BIG));
            notification.put("progress", extras.getInt(Notification.EXTRA_PROGRESS));
            notification.put("progress_indeterminate",
                    String.valueOf(extras.getBoolean(Notification.EXTRA_PROGRESS_INDETERMINATE)));
            notification.put("progress_max", String.valueOf(extras.getInt(Notification.EXTRA_PROGRESS_MAX)));
            notification.put("people", extras.getStringArray(Notification.EXTRA_PEOPLE));
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return notification;
}

From source file:android.support.car.ui.CarNavExtender.java

/**
 * Reconstruct a CarNavExtender from an existing notification. Can be used to retrieve values.
 *
 * @param notification The notification to retrieve the values from.
 *///from   w ww.  ja  va 2s  . com
public CarNavExtender(@NonNull Notification notification) {
    Bundle extras = NotificationCompat.getExtras(notification);
    if (extras == null) {
        return;
    }
    Bundle b = extras.getBundle(EXTRA_CAR_EXTENDER);
    if (b == null) {
        return;
    }

    mIsExtended = b.getBoolean(EXTRA_IS_EXTENDED);
    mContentId = (Long) b.getSerializable(EXTRA_CONTENT_ID);
    // The ternary guarantees that we return either TYPE_HERO or TYPE_NORMAL.
    mType = (b.getInt(EXTRA_TYPE, TYPE_NORMAL) == TYPE_HERO) ? TYPE_HERO : TYPE_NORMAL;
    mContentTitle = b.getCharSequence(Notification.EXTRA_TITLE);
    mContentText = b.getCharSequence(Notification.EXTRA_TEXT);
    mSubText = b.getCharSequence(EXTRA_SUB_TEXT);
    mLargeIcon = b.getParcelable(Notification.EXTRA_LARGE_ICON);
    mActionIcon = b.getInt(EXTRA_ACTION_ICON);
    mContentIntent = b.getParcelable(EXTRA_CONTENT_INTENT);
    mColor = b.getInt(EXTRA_COLOR, Notification.COLOR_DEFAULT);
    mNightColor = b.getInt(EXTRA_NIGHT_COLOR, Notification.COLOR_DEFAULT);
    mShowInStream = b.getBoolean(EXTRA_STREAM_VISIBILITY, true);
    mShowAsHeadsUp = b.getBoolean(EXTRA_HEADS_UP_VISIBILITY);
    mIgnoreInStream = b.getBoolean(EXTRA_IGNORE_IN_STREAM);
}

From source file:android.support.car.ui.CarNavExtender.java

@Override
public NotificationCompat.Builder extend(NotificationCompat.Builder builder) {
    Bundle b = new Bundle();
    b.putBoolean(EXTRA_IS_EXTENDED, true);
    b.putSerializable(EXTRA_CONTENT_ID, mContentId);
    b.putInt(EXTRA_TYPE, mType);//ww w.  j av  a2 s .c  o  m
    b.putCharSequence(Notification.EXTRA_TITLE, mContentTitle);
    b.putCharSequence(Notification.EXTRA_TEXT, mContentText);
    b.putCharSequence(EXTRA_SUB_TEXT, mSubText);
    b.putParcelable(Notification.EXTRA_LARGE_ICON, mLargeIcon);
    b.putInt(EXTRA_ACTION_ICON, mActionIcon);
    b.putParcelable(EXTRA_CONTENT_INTENT, mContentIntent);
    b.putInt(EXTRA_COLOR, mColor);
    b.putInt(EXTRA_NIGHT_COLOR, mNightColor);
    b.putBoolean(EXTRA_STREAM_VISIBILITY, mShowInStream);
    b.putBoolean(EXTRA_HEADS_UP_VISIBILITY, mShowAsHeadsUp);
    b.putBoolean(EXTRA_IGNORE_IN_STREAM, mIgnoreInStream);
    builder.getExtras().putBundle(EXTRA_CAR_EXTENDER, b);
    return builder;
}

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

@TargetApi(Build.VERSION_CODES.KITKAT)
@NonNull//from w ww. j  a v a  2 s  .c  om
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;
}