你好程序员你好吗?我有一点问题。
我正在使用Accessibility Service
来阅读Notification
标题,文字,但问题是notification.bigContentView
,notification.contentView
始终返回null。在remoteViews对象上,它始终返回null。我正在使用Android Marshmallow和Nougat来测试此代码。我认为remotViews总是在棒棒糖上方返回null。如果是,那么我如何在我的Accessibility Service
中阅读这些数据。
代码在这里:
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
Log.v("Tortuga","FML");
if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
Log.v("Tortuga","Recieved event");
Parcelable data = event.getParcelableData();
if (data instanceof Notification&&data!=null) {
Log.v("Tortuga","Recieved notification");
Notification notification = (Notification) event.getParcelableData();
RemoteViews views = notification.contentView;
if (views==null){
views = notification.bigContentView;
secretClass = views.getClass();
}else
{
secretClass = views.getClass();
}
try {
Map<Integer, String> text = new HashMap<Integer, String>();
Field outerFields[] = secretClass.getDeclaredFields();
for (int i = 0; i < outerFields.length; i++) {
if (!outerFields[i].getName().equals("mActions")) continue;
outerFields[i].setAccessible(true);
ArrayList<Object> actions = (ArrayList<Object>) outerFields[i]
.get(views);
for (Object action : actions) {
Field innerFields[] = action.getClass().getDeclaredFields();
Object value = null;
Integer type = null;
Integer viewId = null;
for (Field field : innerFields) {
field.setAccessible(true);
if (field.getName().equals("value")) {
value = field.get(action);
} else if (field.getName().equals("type")) {
type = field.getInt(action);
} else if (field.getName().equals("viewId")) {
viewId = field.getInt(action);
}
}
if (type == 9 || type == 10) {
text.put(viewId, value.toString());
}
}
System.out.println("title is: " + text.get(16908310));
System.out.println("info is: " + text.get(16909082));
System.out.println("text is: " + text.get(16908358));
}
} catch (Exception e) {
e.printStackTrace();
}
String pkg=event.getPackageName().toString();
startService(new Intent(this,Send_Notification.class));
stopService(new Intent(this,Send_Notification.class));
}else {
Toast.makeText(this, "null event", Toast.LENGTH_SHORT).show();
}
}
}
答案 0 :(得分:1)
辅助功能服务无法访问实际的视图对象,因此无法使用。数据实际存储在Accessibility事件中。从辅助功能服务的角度来看,通知的文本通常存储在适当通知类型的event.getText()
属性中。