Android 如何从通知附加中读取whatsapp消息

Android 如何从通知附加中读取whatsapp消息,android,mobile,bitmap,notifications,whatsapp,Android,Mobile,Bitmap,Notifications,Whatsapp,嗨,我正在开发一个应用程序,在这个应用程序中我必须阅读whatsapp上的图片。我可以使用以下代码行将第一个图像读取为位图: Bitmap btm = (Bitmap) sbn.getNotification().extras.get(Notification.EXTRA_PICTURE); 问题是,如果我收到多个图像,我会得到空值。如何解决此问题?这是NotificationListenerService: package com.etaure.callany.testwhatsappim

嗨,我正在开发一个应用程序,在这个应用程序中我必须阅读whatsapp上的图片。我可以使用以下代码行将第一个图像读取为位图:

Bitmap btm = (Bitmap) sbn.getNotification().extras.get(Notification.EXTRA_PICTURE); 

问题是,如果我收到多个图像,我会得到空值。如何解决此问题?

这是
NotificationListenerService

package com.etaure.callany.testwhatsappimage;

import android.accounts.AccountManager;
import android.app.Notification;
import android.content.Intent;
import android.graphics.Bitmap;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.text.TextUtils;
import android.util.Log;

import org.json.JSONArray;

/**
 * Created by administrator on 03/11/2015.
 */
public class MyNotificationListner extends NotificationListenerService {

    static int i = 0;

    @Override
    public void onNotificationPosted(StatusBarNotification sbn) {

        if (sbn.getPackageName().equals("com.whatsapp")) {

            Bitmap btm = (Bitmap) sbn.getNotification().extras.get(Notification.EXTRA_PICTURE);

        }
    }

    @Override
    public void onNotificationRemoved(StatusBarNotification sbn) {
        Log.w("Test", "NotificationRemoved");
    }
}

这是一段为您解析whatsapp图像并在logcat all base64字符串上显示(如果您愿意)的代码!享受

`


`

whatsapp应用程序中的图像是如何传递的?如何从其他应用程序中提取图像?张贴2行代码对任何人都没有帮助我只需要阅读图片!!您将在下面找到通知列表的代码!
           if (extras.containsKey(Notification.EXTRA_PICTURE)) {
            bmp = (Bitmap) extras.get(Notification.EXTRA_PICTURE);
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            bmp.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
            byteArrayS = byteArrayOutputStream .toByteArray();
            encoded = Base64.encodeToString(byteArrayS, Base64.DEFAULT);

            final int LOGCAT_MAX_LENGTH = 3950;
            if (BuildConfig.DEBUG) {
                while (encoded.length() > LOGCAT_MAX_LENGTH) {
                    int substringIndex = encoded.lastIndexOf(",", LOGCAT_MAX_LENGTH);
                    if (substringIndex == -1)
                        substringIndex = LOGCAT_MAX_LENGTH;
                    Log.d("encode", encoded.substring(0, substringIndex));
                    encoded = encoded.substring(substringIndex).trim();
                }
                Log.d("encode", encoded);
            }

        }