Android 在通知中显示图像的缩略图

Android 在通知中显示图像的缩略图,android,google-cloud-messaging,thumbnails,Android,Google Cloud Messaging,Thumbnails,我正在使用GCM推送通知。 在一些通知中,我正在推送文本和图像的组合。但是我只需要在用户单击通知后显示图像,否则我应该提供该图像的缩略图,并将其显示为该通知的一部分。 为此,我应该在哪里更改代码。?在GCM服务器或android应用程序端 下面是我正在做的代码,它将Base64字符串转换为位图。我需要的是通知此图像的缩略图。如果有任何可以生成图像缩略图的代码就足够了 GCM侦听器服务。 @Override public void onMessageReceived(Strin

我正在使用GCM推送通知。 在一些通知中,我正在推送文本和图像的组合。但是我只需要在用户单击通知后显示图像,否则我应该提供该图像的缩略图,并将其显示为该通知的一部分。 为此,我应该在哪里更改代码。?在GCM服务器或android应用程序端

下面是我正在做的代码,它将Base64字符串转换为位图。我需要的是通知此图像的缩略图。如果有任何可以生成图像缩略图的代码就足够了

GCM侦听器服务。

  @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());
            }

我还使用了另一种方法,在下载完成后,图像URL被传递,图像在后台下载。对于这两种方法,我都需要生成图像的缩略图。

在您的情况下,我认为您应该更改
服务器端的代码,并相应地更改要显示为缩略图的图像url。然后使用
位图显示通知。有关更多信息,请查看。@bjiang谢谢你提供的信息。我已经看到了。是否有任何方法可以从完整图像的BASE-64字符串生成缩略图?