Example usage for android.app Notification hashCode

List of usage examples for android.app Notification hashCode

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public native int hashCode();

Source Link

Document

Returns a hash code value for the object.

Usage

From source file:com.playtech.ezpush.gcm.GcmIntentService.java

private void showNotification(Bundle extras) {

    Intent intent = new Intent(getApplicationContext(), MainActivity.class);

    NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(this.NOTIFICATION_SERVICE);
    CharSequence message = extras.getString(EXTRA_MESSAGE);
    intent.putExtra(NOTIFICATION_MESSAGE, message);

    CharSequence title = extras.getString(EXTRA_HEADER);
    if (title == null)
        title = NOTIFICATION_TITLE;/*  w ww  . j a va 2 s  .  c o m*/

    String aid = extras.getString("application_id");
    intent.putExtra("APP_ID", aid);

    String nid = extras.getString("nid");
    intent.putExtra("NOTIFICATION_ID", nid);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    Notification.InboxStyle style = new Notification.InboxStyle();
    style.addLine(message);

    for (String s : extras.keySet()) {
        if (!containsKey(s)) {
            style.addLine(s + ":" + extras.getString(s));
        }
    }

    PendingIntent pendingIntent = PendingIntent.getActivity(this, intent.hashCode(), intent,
            PendingIntent.FLAG_ONE_SHOT);
    Notification.Builder nb = new Notification.Builder(this).setContentTitle(title).setContentText(message)
            .setSmallIcon(R.mipmap.ezpush_logo)
            .setLargeIcon(loadBitmap("http://ursynoteka.pl/wp-content/uploads/2012/04/message_new.png"))
            .setStyle(style).setContentIntent(pendingIntent).setAutoCancel(true);

    if (extras.containsKey(EXTRA_SOUND)) {
        nb.setSound(Uri.parse(extras.getString(EXTRA_SOUND)));
    }
    if (extras.containsKey(EXTRA_BANNER)) {
        Bitmap bitmap = loadBitmap(extras.getString(EXTRA_BANNER));
        if (bitmap != null) {
            NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle()
                    .setBigContentTitle(NOTIFICATION_TITLE).setSummaryText(message).bigPicture(bitmap);
        }
    }
    if (extras.containsKey(EXTRA_ICON)) {
        String iconUrl = extras.getString(EXTRA_ICON);
        Bitmap bitmap = loadBitmap(iconUrl);
        if (bitmap != null) {
            nb.setLargeIcon(bitmap);
        }
    }

    Notification notification = nb.build();

    notificationManager.notify(notification.hashCode(), notification);
}

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  .j a  va2 s .com

    // 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);
}