【发布时间】:2021-06-23 13:43:20
【问题描述】:
我想从发布的任何移动应用程序的通知中获取图标。
为此,我创建了 NotificationListener Service 并覆盖了 on notification Posted 方法。
我尝试了以下方法,但都没有奏效。请有人帮助我是新的和更瘦的。提前致谢。
@Override
public void onNotificationPosted(StatusBarNotification sbn){
Intent intent = new Intent("com.example.notify");
intent.putExtra("Notification sbn", sbn);
sendBroadcast(intent);
}
public class ImageChangeBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
StatusBarNotification sbn = intent.getParcelableExtra("Notification sbn");
Bitmap bitmap = (Bitmap) sbn.getNotification().extras.get(Notification.EXTRA_LARGE_ICON);
image1.setImageBitmap(bitmap);
image2.setImageBitmap(sbn.getNotification().largeIcon);
Notification notification = sbn.getNotification();
notification.getLargeIcon();
image3.setImageIcon(notification.getLargeIcon());
}
}
【问题讨论】:
标签: java android android-studio kotlin notifications