gpt4 book ai didi

java - 我无法在 android 5.1 上获取通知图像,始终返回 null

转载 作者:行者123 更新时间:2023-12-02 02:04:31 29 4
gpt4 key购买 nike

我正在开发一个应用程序,它可以通过通知获取通过 Whatsapp 发送的所有图像,但该功能显然不适用于旧版本的 Android。请帮助我!

public String getBase64(Notification notification){
if(bundle.containsKey(Notification.EXTRA_PICTURE)){
// Log.d("Tem foto","notificação");
String encoded="";

try {
Bitmap bmp = (Bitmap) bundle.get(Notification.EXTRA_PICTURE);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
//base64String = encoded;

}catch(Exception e){
Log.d("erro",e.getMessage());
}

return encoded;
}
else{
//Log.d("key","não tem key");
return "";
}

}

最佳答案

您可能想使用NotificationListenerService

@Override
public void onNotificationPosted(StatusBarNotification statusBarNotification){
String package = statusBarNotification.getPackageName();
Bundle extras = statusBarNotification.getNotification().extras;
try {
PackageManager manager = getPackageManager();
Resources resources = manager.getResourcesForApplication(package);
Drawable icon = resources.getDrawable(iconId);
} catch (Exception e) {
e.printStackTrace();
}
if (extras.containsKey(Notification.EXTRA_PICTURE)) {
// Here you may get the image
Bitmap bmp = (Bitmap) extras.get(Notification.EXTRA_PICTURE);
}
}

关于java - 我无法在 android 5.1 上获取通知图像,始终返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57362966/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com