0

I am using GCM to push notification. In some of the notification i am pushing text and image combination. But i need to show the images only after user click the notification else i should provide a thumbnail of that image should be shown as part of that notification. For that where should i change my code.? In GCM Server or android app side.?

Here is the code what i am doing which will convert Base64 string to bitmap. What i need is thumbnail of this image for notification. If any code which can generate thumbnail of an image should be sufficient.

GCM Listener Service.

  @Override
        public void onMessageReceived(String from, Bundle data) {
                String message = data.getString("SERVER_MESSAGE");
                String imageBitMap= data.getString("IMAGE_BITMAP");
                jsonObject.put("Message", message);
                jsonObject.put("ImageBitMap",decodeImage(imageBitMap));

      sendNotification(jsonObject);
}
    /**
         * Decode a base64 string into a Bitmap
         */
        private static Bitmap decodeImage(String image_data) {
            // Decode the encoded string into largeIcon
            Bitmap largeIcon = null;
            if ((image_data != null) && (!image_data.equals(""))) {
                byte[] decodedImage = Base64.decode(image_data, Base64.DEFAULT);
                if (decodedImage != null) {
                    largeIcon = BitmapFactory.decodeByteArray(decodedImage
                            , 0
                            , decodedImage.length);
                }
            }
            return largeIcon;
        }

    //Notification of Image 
        private void sendNotification(JSONObject jsonObject) {
                String message= null;
                Bitmap bitmap=null;
                try {
                    message = jsonObject.getString("Message");
                    bitmap= (Bitmap) jsonObject.get("ImageBitMap");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                Intent intent = new Intent(this, ManualTestActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                PendingIntent pendingIntent = PendingIntent.getActivity(this, REQ_CODE, intent,
                        PendingIntent.FLAG_ONE_SHOT);

                Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                        .setSmallIcon(getNotificationIcon())
                        .setContentTitle("GCM")
                        .setContentText(message)
                        .setAutoCancel(true)
                        .setSound(defaultSoundUri)
                        .setContentIntent(pendingIntent)
                        .setStyle(new NotificationCompat.BigPictureStyle()
                                .bigPicture(bitmap));

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

                notificationManager.notify(NOTF_ID, notificationBuilder.build());
            }

I have used one more method where image URL is passed and image is getting downloaded in background after download complete i am generating notification.For both the method i need to generate thumbnail of an image.

Madhukar Hebbar
  • 3,113
  • 5
  • 41
  • 69
  • In your case, I think you should change the code on the `server side`, and `change the image url` that you wanna show as thumbnail accordingly. Then shows on the notification by using `bitmap`. For more info, please check out [here](http://stackoverflow.com/a/16007659/4186942). – bjiang Dec 01 '15 at 18:33
  • @bjiang Thanks for the info.I have seen that. Is there any method available which can generate thumbnail from BASE-64 string of a full image? – Madhukar Hebbar Dec 02 '15 at 04:49

0 Answers0