Example usage for android.app NotificationManager notify

List of usage examples for android.app NotificationManager notify

Introduction

In this page you can find the example usage for android.app NotificationManager notify.

Prototype

public void notify(int id, Notification notification) 

Source Link

Document

Post a notification to be shown in the status bar.

Usage

From source file:at.flack.receiver.EMailReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();//from www .j a  v  a 2  s  . c o m
    try {
        if (bundle.getString("type").equals("mail")) {
            sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
            if (!sharedPrefs.getBoolean("notification_mail", true))
                return;
            notify = sharedPrefs.getBoolean("notifications", true);
            vibrate = sharedPrefs.getBoolean("vibration", true);
            headsup = sharedPrefs.getBoolean("headsup", true);
            led_color = sharedPrefs.getInt("notification_light", -16776961);
            boolean all = sharedPrefs.getBoolean("all_mail", true);

            if (notify == false)
                return;

            NotificationCompat.Builder mBuilder = null;
            boolean use_profile_picture = false;
            Bitmap profile_picture = null;

            String origin_name = bundle.getString("senderName").equals("") ? bundle.getString("senderMail")
                    : bundle.getString("senderName");

            try {
                profile_picture = RoundedImageView.getCroppedBitmap(Bitmap.createScaledBitmap(
                        ProfilePictureCache.getInstance(context).get(origin_name), 200, 200, false), 300);
                use_profile_picture = true;
            } catch (Exception e) {
                use_profile_picture = false;
            }

            Resources res = context.getResources();

            int lastIndex = bundle.getString("subject").lastIndexOf("=");
            if (lastIndex > 0 && Base64.isBase64(bundle.getString("subject").substring(0, lastIndex))) {
                mBuilder = new NotificationCompat.Builder(context)
                        .setSmallIcon(R.drawable.raven_notification_icon).setContentTitle(origin_name)
                        .setColor(0xFFFF5722)
                        .setContentText(res.getString(R.string.sms_receiver_new_encrypted_mail))
                        .setAutoCancel(true);
                if (use_profile_picture && profile_picture != null) {
                    mBuilder = mBuilder.setLargeIcon(profile_picture);
                } else {
                    mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name,
                            context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200));
                }
            } else {

                if (bundle.getString("subject").charAt(0) == '%' && (bundle.getString("subject").length() == 10
                        || bundle.getString("subject").length() == 9)) {
                    if (lastIndex > 0 && Base64.isBase64(bundle.getString("subject").substring(1, lastIndex))) {
                        mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name)
                                .setColor(0xFFFF5722)
                                .setContentText(res.getString(R.string.sms_receiver_handshake_received))
                                .setSmallIcon(R.drawable.notification_icon).setAutoCancel(true);
                        if (use_profile_picture && profile_picture != null) {
                            mBuilder = mBuilder.setLargeIcon(profile_picture);
                        } else {
                            mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name,
                                    context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200));
                        }
                    } else {
                        return;
                    }
                } else if (bundle.getString("subject").charAt(0) == '%'
                        && bundle.getString("subject").length() >= 120
                        && bundle.getString("subject").length() < 125) {
                    if (lastIndex > 0 && Base64.isBase64(bundle.getString("subject").substring(1, lastIndex))) {
                        mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name)
                                .setColor(0xFFFF5722)
                                .setContentText(res.getString(R.string.sms_receiver_handshake_received))
                                .setSmallIcon(R.drawable.notification_icon).setAutoCancel(true);
                        if (use_profile_picture && profile_picture != null) {
                            mBuilder = mBuilder.setLargeIcon(profile_picture);
                        } else {
                            mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name,
                                    context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200));
                        }
                    } else {
                        return;
                    }
                } else if (all) { // normal message
                    mBuilder = new NotificationCompat.Builder(context)
                            .setSmallIcon(R.drawable.raven_notification_icon).setContentTitle(origin_name)
                            .setColor(0xFFFF5722).setContentText(bundle.getString("subject"))
                            .setAutoCancel(true).setStyle(
                                    new NotificationCompat.BigTextStyle().bigText(bundle.getString("subject")));

                    if (use_profile_picture && profile_picture != null) {
                        mBuilder = mBuilder.setLargeIcon(profile_picture);
                    } else {
                        mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name,
                                context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200));
                    }
                } else {
                    return;
                }
            }
            // }
            Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            mBuilder.setSound(alarmSound);
            mBuilder.setLights(led_color, 750, 4000);
            if (vibrate) {
                mBuilder.setVibrate(new long[] { 0, 100, 200, 300 });
            }

            Intent resultIntent = new Intent(context, MainActivity.class);
            resultIntent.putExtra("MAIL", bundle.getString("senderMail"));

            TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
            stackBuilder.addParentStack(MainActivity.class);
            stackBuilder.addNextIntent(resultIntent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(1,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(resultPendingIntent);
            if (Build.VERSION.SDK_INT >= 16 && headsup)
                mBuilder.setPriority(Notification.PRIORITY_HIGH);
            if (Build.VERSION.SDK_INT >= 21)
                mBuilder.setCategory(Notification.CATEGORY_MESSAGE);

            final NotificationManager mNotificationManager = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);

            if (!MainActivity.isOnTop)
                mNotificationManager.notify(9, mBuilder.build());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.nbempire.dentalnavarra.component.service.RemembersService.java

private void showNotification(String title, String text, Remember remember) {
    Log.d(TAG, "Building notification...");

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.notification).setContentTitle(title).setContentText(text)
            .setAutoCancel(true);/*w w  w.jav a 2 s.co  m*/

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, DentalNavarraActivity.class);
    if (remember != null) {
        Log.i(TAG, "Adding extra parameter to notification result intent, message: " + remember.getMessage());
        resultIntent.putExtra(NOTIFICATION_INTENT_PARAMETER_MESSAGE, remember.getMessage());
        Log.i(TAG, "Adding extra parameter to notification result intent, meetingDate: "
                + remember.getMeetingDate());
        resultIntent.putExtra(NOTIFICATION_INTENT_PARAMETER_MEETING_DATE, remember.getMeetingDate());
        Log.i(TAG, "Adding extra parameter to notification result intent, treatments: "
                + remember.getTreatments());
        resultIntent.putExtra(NOTIFICATION_INTENT_PARAMETER_TREATMENTS, remember.getTreatments());
    }

    // The stack builder object will contain an artificial back stack for the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(DentalNavarraActivity.class);

    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);

    Notification notification = mBuilder.build();
    notification.defaults |= Notification.DEFAULT_ALL;

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    // mId allows you to update the notification later on.
    //  TODO : Functionality : Should I unhard-code this ID?
    mNotificationManager.notify(44, notification);

    Log.d(TAG, "Notification added to status bar: " + text);
}

From source file:br.ajmarques.cordova.plugin.localnotification.Receiver.java

/**
 * Zeigt die Notification an.//from   w  ww.  j a  v a  2 s .  co m
 */
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private void showNotification(NotificationCompat.Builder notification) {
    NotificationManager mgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    int id = 0;

    try {
        id = Integer.parseInt(options.getId());
    } catch (Exception e) {
    }

    if (Build.VERSION.SDK_INT < 16) {
        // build notification for HoneyComb to ICS
        mgr.notify(id, notification.getNotification());
    } else if (Build.VERSION.SDK_INT > 15) {
        // Notification for Jellybean and above
        mgr.notify(id, notification.build());
    }
}

From source file:com.arellomobile.android.push.PushGCMIntentService.java

private static void generateNotification(Context context, Intent intent, Handler handler) {
    Bundle extras = intent.getExtras();/*from   www .  j  av  a  2 s.c o  m*/
    if (extras == null) {
        return;
    }

    extras.putBoolean("foregroud", GeneralUtils.isAppOnForeground(context));

    String title = (String) extras.get("title");
    String link = (String) extras.get("l");

    // empty message with no data
    Intent notifyIntent;
    if (link != null) {
        // we want main app class to be launched
        notifyIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
        notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    } else {
        notifyIntent = new Intent(context, PushHandlerActivity.class);
        notifyIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);

        // pass all bundle
        notifyIntent.putExtra("pushBundle", extras);
    }

    // first string will appear on the status bar once when message is added
    CharSequence appName = context.getPackageManager().getApplicationLabel(context.getApplicationInfo());
    if (null == appName) {
        appName = "";
    }

    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationFactory notificationFactory;

    //is this banner notification?
    String bannerUrl = (String) extras.get("b");

    //also check that notification layout has been placed in layout folder
    int layoutId = context.getResources().getIdentifier(BannerNotificationFactory.sNotificationLayout, "layout",
            context.getPackageName());

    if (layoutId != 0 && bannerUrl != null) {
        notificationFactory = new BannerNotificationFactory(context, extras, appName.toString(), title,
                PushManager.sSoundType, PushManager.sVibrateType);
    } else {
        notificationFactory = new SimpleNotificationFactory(context, extras, appName.toString(), title,
                PushManager.sSoundType, PushManager.sVibrateType);
    }
    notificationFactory.generateNotification();
    notificationFactory.addSoundAndVibrate();
    notificationFactory.addCancel();

    Notification notification = notificationFactory.getNotification();

    notification.contentIntent = PendingIntent.getActivity(context, 0, notifyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    if (mSimpleNotification) {
        manager.notify(PushManager.MESSAGE_ID, notification);
    } else {
        manager.notify(PushManager.MESSAGE_ID++, notification);
    }

    generateBroadcast(context, extras);
}

From source file:ota.otaupdates.MainActivity.java

private void create_notification(int id, String title, String content) {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon((android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP
                    ? R.drawable.app_icon_notification
                    : R.drawable.app_icon))
            .setContentTitle(title).setContentText(content);

    Intent resultIntent = new Intent(this, MainActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(id, mBuilder.build());
}

From source file:com.carpool.dj.carpool.model.GcmIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///from   w w  w .ja v  a 2s . co m
@SuppressWarnings("deprecation")
private static void generateNotification(Context context, String message, Bundle data, String type) {

    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    // Notification notification = new Notification(icon, message, when);
    Notification notification = new Notification.Builder(context)
            .setContentTitle(Utils.nowActivity.getString(R.string.app_name)).setContentText(message)
            .setSmallIcon(icon).setWhen(when).setSound(alarmSound).build();

    // String title = context.getString(R.string.app_name);

    Intent notificationIntent = null;
    if ("CarEvent".equals(type)) {
        notificationIntent = new Intent(context, ContentActivity.class);
    } else {
        return;
    }
    notificationIntent.putExtras(data);
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setLatestEventInfo(context, Utils.nowActivity.getString(R.string.app_name), message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    notificationManager.notify(0, notification);

}

From source file:ar.com.martinrevert.argenteam.GcmIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///from ww w  .  j  a  va2 s  .c o  m
private void generarNotification(Context context, String message, String urlimagen, String urlarticulo,
        String tipo, String fecha) {
    SharedPreferences preferencias = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    boolean vib = preferencias.getBoolean("vibraoff", false);
    boolean movieoff = preferencias.getBoolean("movieoff", false);
    boolean tvoff = preferencias.getBoolean("tvoff", false);
    String ringmovie = preferencias.getString("prefRingtonemovie", "");
    String ringtv = preferencias.getString("prefRingtonetv", "");
    //Todo traducir ticker
    String ticker = "Nuevo subttulo " + tipo + " en aRGENTeaM";

    Random randomGenerator = new Random();
    int randomInt = randomGenerator.nextInt(100);

    Bitmap bitmap = getRemoteImage(urlimagen, tipo);

    Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

    int dash = 500;
    int short_gap = 200;

    long[] pattern = { 0, // Start immediately
            dash, short_gap, dash, short_gap, dash };

    Intent notificationIntent;
    String ringtone;
    int ledlight;

    if (tipo.equalsIgnoreCase("Movie")) {
        ringtone = ringmovie;
        notificationIntent = new Intent(context, Peli.class);
        ledlight = preferencias.getInt("ledMovie", 0);

    } else {
        notificationIntent = new Intent(context, Tv.class);
        ringtone = ringtv;
        ledlight = preferencias.getInt("ledTV", 0);
        System.out.println(ledlight);
    }
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("passed", urlarticulo);

    PendingIntent pendingIntent;

    pendingIntent = PendingIntent.getActivity(context, randomInt, notificationIntent, 0);

    Notification myNotification;
    myNotification = new NotificationCompat.Builder(context).setPriority(1).setContentTitle(message)
            .setTicker(ticker).setLights(ledlight, 300, 300).setWhen(System.currentTimeMillis())
            .setContentIntent(pendingIntent).setSound(Uri.parse(ringtone)).setAutoCancel(true)
            .setSmallIcon(R.drawable.ic_stat_ic_argenteam_gcm).build();

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        RemoteViews views;
        views = new RemoteViews(getPackageName(), R.layout.custom_notification);
        views.setImageViewBitmap(R.id.big_picture, bitmap);
        views.setImageViewBitmap(R.id.big_icon,
                BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_ic_argenteam_gcm));
        views.setTextViewText(R.id.title, message);
        myNotification.bigContentView = views;
    }

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    if (movieoff && tipo.equalsIgnoreCase("Movie")) {
        if (vib) {
            v.vibrate(pattern, -1);
        }
        notificationManager.notify(randomInt, myNotification);

    }

    if (tvoff && tipo.equalsIgnoreCase("Serie TV")) {
        if (vib) {
            v.vibrate(pattern, -1);
        }
        notificationManager.notify(randomInt, myNotification);

    }

}

From source file:it.mb.whatshare.SendToGCMActivity.java

@SuppressWarnings("deprecation")
private void showNotification(int sharedWhat, boolean sharedViaWhatsapp) {
    String title = getString(R.string.whatshare);
    Intent onNotificationDiscarded = new Intent(this, SendToGCMActivity.class);
    PendingIntent notificationIntent = PendingIntent.getActivity(this, 0, onNotificationDiscarded, 0);
    Notification notification = null;
    int notificationIcon = sharedViaWhatsapp ? R.drawable.notification_icon
            : R.drawable.whatshare_logo_notification;
    int notificationNumber = notificationCounter.incrementAndGet();
    String content = getString(R.string.share_success, getString(sharedWhat), outboundDevice.type);
    // @formatter:off
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(notificationIcon, 0)
            .setContentTitle(title).setContentText(content).setTicker(content)
            .setContentIntent(notificationIntent)
            .setDeleteIntent(PendingIntent.getActivity(this, 0, onNotificationDiscarded, 0))
            .setNumber(notificationNumber);
    // @formatter:on
    if (Build.VERSION.SDK_INT > 15) {
        notification = buildForJellyBean(builder);
    } else {/*from w w w .j  a v a 2  s.  c  om*/
        notification = builder.getNotification();
    }
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // cancel previous notification to clean up garbage in the status bar
    nm.cancel(notificationNumber - 1);
    nm.notify(notificationNumber, notification);
}

From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.SystemMonitor.java

private int systemNotice() {
    int t = START_STICKY;
    Log.e(SystemMonitor.class.getSimpleName(), "call me redundant BABY!  onStartCommand service");

    int myID = android.os.Process.myPid();
    // The intent to launch when the user clicks the expanded notification
    Intent intent = new Intent(this, MyHealthHubWithFragments.class);
    // Intent intent = new Intent();
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, 0);

    Notification notice = new Notification.Builder(getApplicationContext()).setSmallIcon(R.drawable.ic_launcher)
            .setWhen(System.currentTimeMillis()).setContentTitle(getPackageName())
            .setContentText("System Monitor running").setContentIntent(pendIntent).getNotification();

    notice.flags |= Notification.FLAG_AUTO_CANCEL;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(myID, notice);

    return t;//from   www  .  jav a 2 s  .  co m
}

From source file:ar.fiuba.jobify.JobifyChat.java

/**
 * Called when message is received.//ww w  .  j a v  a2  s. c o  m
 *
 * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
 */
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // [START_EXCLUDE]
    // There are two types of messages data messages and notification messages. Data messages are handled
    // here in onMessageReceived whether the app is in the foreground or background. Data messages are the type
    // traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app
    // is in the foreground. When the app is in the background an automatically generated notification is displayed.
    // When the user taps on the notification they are returned to the app. Messages containing both notification
    // and data payloads are treated as notification messages. The Firebase console always sends notification
    // messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options
    // [END_EXCLUDE]
    // Not getting messages here? See why this may be: https://goo.gl/39bRNJ
    Log.d(TAG, "From: " + remoteMessage.getFrom());

    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        String body = remoteMessage.getData() + "";
        Log.d(TAG, "Message data payload: " + body);
        JsonParser parser = new JsonParser();
        //JsonObject message = parser.parse(body).getAsJsonObject();
        JSONObject message = null;
        try {
            message = new JSONObject(body);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        if (message.has("mensaje")) {

            long sender = 0, receiver = 0;
            try {
                receiver = message.getJSONObject("mensaje").getLong("to");
                sender = message.getJSONObject("mensaje").getLong("from");
            } catch (JSONException e) {
                e.printStackTrace();
            }

            long currentId = getSharedPreferences(getString(R.string.shared_pref_connected_user), 0)
                    .getLong(getString(R.string.stored_connected_user_id), -1);
            //Log.d("MYTAG", editor.g getLong( getString(R.string.stored_connected_user_id)));

            if (receiver != currentId) {
                // la app no esta abierta
                return;
            }

            if (!(ConversacionActivity.activityVisible && ConversacionActivity.corresponsalID == sender)) {
                NotificationCompat.Builder mBuilder = null;
                try {
                    mBuilder = new NotificationCompat.Builder(this).setContentTitle("Nuevo mensaje")
                            .setSmallIcon(R.drawable.common_google_signin_btn_icon_dark).setAutoCancel(true)
                            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.mensaje))
                            .setSmallIcon(R.drawable.logo_v2_j_square)
                            .setContentText(message.getJSONObject("mensaje").getString("message"));
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                //ConversacionActivity.

                Intent resultIntent = new Intent(this, ConversacionActivity.class);
                TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
                stackBuilder.addParentStack(ConversacionActivity.class);

                // Adds the Intent that starts the Activity to the top of the stack
                stackBuilder.addNextIntent(resultIntent);
                resultIntent.putExtra(ConversacionActivity.CORRESPONSAL_ID_MESSAGE, (long) sender);
                PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                mBuilder.setContentIntent(resultPendingIntent);

                NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                        Context.NOTIFICATION_SERVICE);

                Random r = new Random();
                mNotificationManager.notify(r.nextInt(1000000000), mBuilder.build());

            }
            // notify chat
            try {
                EventBus.getDefault().post(new MessageEvent(message.getJSONObject("mensaje")));
            } catch (JSONException e) {
                e.printStackTrace();
            }

        } else if (message.has("solicitud")) {

            long receiver = 0;
            try {
                receiver = message.getJSONObject("solicitud").getLong("toId");
            } catch (JSONException e) {
                e.printStackTrace();
            }

            long currentId = getSharedPreferences(getString(R.string.shared_pref_connected_user), 0)
                    .getLong(getString(R.string.stored_connected_user_id), -1);
            //Log.d("MYTAG", editor.g getLong( getString(R.string.stored_connected_user_id)));

            if (receiver != currentId) {
                // la app no esta abierta
                return;
            }

            NotificationCompat.Builder mBuilder = null;
            try {
                mBuilder = new NotificationCompat.Builder(this).setContentTitle("Nueva solicitud")
                        .setSmallIcon(R.drawable.common_google_signin_btn_icon_dark).setAutoCancel(true)
                        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.solicitud))
                        .setSmallIcon(R.drawable.logo_v2_j_square)
                        .setContentText(message.getJSONObject("solicitud").getString("fromNombre"));
            } catch (JSONException e) {
                e.printStackTrace();
            }

            Intent resultIntent = new Intent(this, UserListActivity.class);
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
            stackBuilder.addParentStack(UserListActivity.class);

            // Adds the Intent that starts the Activity to the top of the stack
            stackBuilder.addNextIntent(resultIntent);
            resultIntent.putExtra(UserListActivity.LIST_MODE_MESSAGE, UserListActivity.MODE_SOLICITUDES);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(resultPendingIntent);

            NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                    Context.NOTIFICATION_SERVICE);

            Random r = new Random();
            mNotificationManager.notify(r.nextInt(1000000000), mBuilder.build());

        }
        // if this is a notification:
        // TODO
        // here we call the callback to the activity

        // if this is a message:

    }

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
    }

    // Also if you intend on generating your own notifications as a result of a received FCM
    // message, here is where that should be initiated. See sendNotification method below.
}