【发布时间】:2017-08-30 15:27:25
【问题描述】:
使用辅助功能服务我能够阅读通知栏标题和消息,我面临的问题是当第一个通知出现时我正在完美地阅读所有这些但在第一次通知之后我只得到标题和文本“你有2 条消息”等等,而不是整个消息。 等待您的专家建议。
代码:
@Override
protected void onServiceConnected()
{
Log.d("AccessibilityServiceNotification", "ServiceConnected");
try
{
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_ALL_MASK;
info.notificationTimeout = 100;
setServiceInfo(info);
}
catch(Exception e)
{
Log.d("ERROR onServiceConnected", e.toString());
}
}
@Override
public void onAccessibilityEvent(AccessibilityEvent event)
{
try
{
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Parcelable data = event.getParcelableData();
if(data !=null)
{
Notification notification = (Notification) data;
RemoteViews remoteView = notification.bigContentView;
ViewGroup localView = (ViewGroup) inflater.inflate(remoteView.getLayoutId(), null);
remoteView.reapply(getApplicationContext(), localView);
Resources resources = null;
PackageManager pkm = getPackageManager();
try
{
resources = pkm.getResourcesForApplication("com.user.package");
}
catch (NameNotFoundException e)
{
e.printStackTrace();
}
if (resources == null)
return;
int TITLE = resources.getIdentifier("android:id/title", null, null);
int INBOX = resources.getIdentifier("android:id/big_text", null, null);
int TEXT = resources.getIdentifier("android:id/text", null, null);
String packagename = String.valueOf(event.getPackageName());
title = (TextView) localView.findViewById(TITLE);
inbox = (TextView) localView.findViewById(INBOX);
text = (TextView) localView.findViewById(TEXT);
Log.d("NOTIFICATION Package : ", packagename);
Log.d("NOTIFICATION Title : ", title.getText().toString());
Log.d("NOTIFICATION You have got x messages : ", text.getText().toString());
Log.d("NOTIFICATION inbox : ", inbox.getText().toString());
}
}
catch(Exception e)
{
Log.e("onAccessibilityEvent ERROR", e.toString());
}
}
示例通知 1:
包:com.whatsapp, 标题:你好, 留言:你好吗
示例通知 2:
包:com.whatsapp, 标题:你好, 消息:你有 2 条消息(而不是:你在做什么)
【问题讨论】:
标签: java android notifications accessibilityservice