@@ -0,0 +1,2900 @@
+package com.google.firebase.udacity.friendlychat;%0A%0A/**%0A * Created by kashyap on 19/2/17.%0A */%0A%0A%0Aimport android.app.NotificationManager;%0Aimport android.app.PendingIntent;%0Aimport android.content.Context;%0Aimport android.content.Intent;%0Aimport android.media.RingtoneManager;%0Aimport android.support.v4.app.NotificationCompat;%0Aimport android.util.Log;%0A%0Aimport com.google.firebase.messaging.FirebaseMessagingService;%0Aimport com.google.firebase.messaging.RemoteMessage;%0A%0Aimport java.io.UnsupportedEncodingException;%0Aimport java.net.URLDecoder;%0A%0A%0Apublic class MyFirebaseMessagingService extends FirebaseMessagingService %7B%0A%0A    private static final String TAG = %22MyGcmListenerService%22;%0A%0A    @Override%0A    public void onMessageReceived(RemoteMessage message) %7B%0A%0A        String image = message.getNotification().getIcon();%0A        String title = message.getNotification().getTitle();%0A        String text = message.getNotification().getBody();%0A        String sound = message.getNotification().getSound();%0A%0A        int id = 0;%0A        Object obj = message.getData().get(%22id%22);%0A        if (obj != null) %7B%0A            id = Integer.valueOf(obj.toString());%0A        %7D%0A%0A        this.sendNotification(new NotificationData(image, id, title, text, sound));%0A    %7D%0A%0A    /**%0A     * Create and show a simple notification containing the received GCM message.%0A     *%0A     * @param notificationData GCM message received.%0A     */%0A    private void sendNotification(NotificationData notificationData) %7B%0A%0A        Intent intent = new Intent(this, MainActivity.class);%0A        intent.putExtra(NotificationData.TEXT, notificationData.getTextMessage());%0A%0A        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);%0A        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,%0A                PendingIntent.FLAG_ONE_SHOT);%0A%0A        NotificationCompat.Builder notificationBuilder = null;%0A        try %7B%0A%0A            notificationBuilder = new NotificationCompat.Builder(this)%0A                    .setSmallIcon(R.mipmap.ic_launcher)%0A                    .setContentTitle(URLDecoder.decode(notificationData.getTitle(), %22UTF-8%22))%0A                    .setContentText(URLDecoder.decode(notificationData.getTextMessage(), %22UTF-8%22))%0A                    .setAutoCancel(true)%0A                    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))%0A                    .setContentIntent(pendingIntent);%0A%0A        %7D catch (UnsupportedEncodingException e) %7B%0A            e.printStackTrace();%0A        %7D%0A%0A        if (notificationBuilder != null) %7B%0A            NotificationManager notificationManager =%0A                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);%0A            notificationManager.notify(notificationData.getId(), notificationBuilder.build());%0A        %7D else %7B%0A            Log.d(TAG, %22N%C3%A3o foi poss%C3%ADvel criar objeto notificationBuilder%22);%0A        %7D%0A    %7D%0A%7D%0A

Add Notification