有没有办法获取系统通知的图标?
我可以通过无障碍服务收到包裹通知。我什至可以从中获取图标的 id,但我被困在那里。我不知道如何使用 id 来获取实际的位图,以便我可以显示它,因为它不是来自我的 apk。
到目前为止,这是我的代码:
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
Log.d("onAccessibilityEvent");
if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
if (event.getParcelableData() instanceof Notification) {
Notification notification = (Notification) event.getParcelableData();
Log.d("ticker: " + notification.tickerText);
Log.d("icon: " + notification.icon);
Log.d("largeIcon: " + notification.largeIcon);
}
Log.d("notification: " + event.getText());
}
}
尝试使用此 id 会导致
android.content.res.Resources$NotFoundException:资源 ID #0x7f0200ad
所以我通过在 RemoteViews 中搜索第一个 ImageView 来完成此任务
extractImage(notification.contentView);
...
private void extractImage(RemoteViews views) {
LinearLayout ll = new LinearLayout(getApplicationContext());
View view = views.apply(getApplicationContext(), ll);
drawable = searchForBitmap(view);
Log.d("Drawable: " + drawable);
}
private Drawable searchForBitmap(View view) {
if (view instanceof ImageView) {
return ((ImageView) view).getDrawable();
}
if (view instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) view;
for (int i = 0; i < viewGroup.getChildCount(); i++) {
Drawable result = searchForBitmap(viewGroup.getChildAt(i));
if (result != null) {
return result;
}
}
}
return null;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)