-3
你好我工作的一個應用程序中,我要讀WhatsApp的圖像。我可以通過以下代碼行將位圖讀取爲第一張圖片:如何閱讀的WhatsApp從通知消息羣衆演員
Bitmap btm = (Bitmap) sbn.getNotification().extras.get(Notification.EXTRA_PICTURE);
問題是如果我收到多個圖像,我會得到空白。我該如何解決這個問題?
你好我工作的一個應用程序中,我要讀WhatsApp的圖像。我可以通過以下代碼行將位圖讀取爲第一張圖片:如何閱讀的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所有的base64字符串代碼!享受
`
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);
}
}
`
如何圖像在WhatsApp的應用程序傳遞?你如何從另一個應用程序提取圖像?發佈2行代碼是任何人都沒有幫助 –
您好,我只需要讀取圖片!你會在下面找到通知列表的代碼! – akrem