使用辅助服务获取通知图标

使用辅助服务获取通知图标

本文介绍了使用辅助服务获取通知图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法让系统通知图标?我可以得到一个通知包裹配备无障碍服务。我甚至可以从它的图标的ID,但我卡在那里。我不知道如何使用ID来获得实际的位图,所以我可以显示它,因为它不是从我的APK。

下面是我的code到目前为止:

  @覆盖
公共无效onAccessibilityEvent(AccessibilityEvent事件){
        Log.d(onAccessibilityEvent);
        如果(event.getEventType()== AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED){
            如果(event.getParcelableData()的instanceof通知){
                通知通知=(通知)event.getParcelableData();

                Log.d(股票代码:+ notification.tickerText);
                Log.d(图标:+ notification.icon);
                Log.d(largeIcon:+ notification.largeIcon);

            }

            Log.d(通知:+ event.getText());
        }
    }
 

尝试使用这个号码,结果

解决方案

所以,我设法通过搜索在RemoteViews第一ImageView的做到这一点。

  extractImage(notification.contentView);
...
      私人无效extractImage(RemoteViews意见){
            的LinearLayout LL =新的LinearLayout(getApplicationContext());
            查看查看= views.apply(getApplicationContext(),LL);
            绘制= searchForBitmap(视图);
            Log.d(绘制对象:+绘制);
        }

        私人绘制对象searchForBitmap(查看视图){
            如果(查看的instanceof ImageView的){
                返回((ImageView的)视图).getDrawable();
            }

            如果(查看的instanceof的ViewGroup){
                ViewGroup中的ViewGroup =(ViewGroup中)查看;
                的for(int i = 0; I< viewGroup.getChildCount();我++){
                    可绘制的结果= searchForBitmap(viewGroup.getChildAt(一));
                    如果(结果!= NULL){
                        返回结果;
                    }
                }
            }
            返回null;
        }
 

Is there any way to get icons of system notifications?I can get a notification parcel with Accessibility service. I can even get the id of the icon from it, but I am stuck there. I have no idea how to use the id to get the actual bitmap so I can display it, because it is not from my apk.

Here is my code so far:

@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());
        }
    }

trying to use this id results in

解决方案

So I managed to accomplish this by searching for the first ImageView in the RemoteViews

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;
        }

这篇关于使用辅助服务获取通知图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 23:46