十句代码搞定消息拦截(微信、qq、微博、tim等等啦)
废话不多说直接上代码
if (!"".equals(event.getText().toString()) && event.getText().toString() != null) {
for (String str : keyWordList) {
if (event.getText().toString().contains(str)) {
AccessibilityNodeInfo accessibilityNodeInfo = getRootInActiveWindow();
if (accessibilityNodeInfo == null) {
return;
}
Toast.makeText(this,"注意你的言语",Toast.LENGTH_LONG).show();
List<AccessibilityNodeInfo> editNodeInfo = accessibilityNodeInfo.findAccessibilityNodeInfosByText(str);
if (editNodeInfo != null && editNodeInfo.size()>=0) {
Bundle arguments = new Bundle();
arguments.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, " ");
editNodeInfo.get(0).performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments);
}
}
}
}
对于微信的自定义view获取不到文本内容暂时一种方案是发送长按事件,激活复制读取粘贴板内容,这种方案并不太好,不过想不到其它方法了。