我正在寻找一种从 map 导航中获取说明的方法。
目前我认为唯一可能的方法是读取 map 导航放置在顶部的通知数据。我相信这是唯一方法的原因来自这个 post 。
我尝试使用 OnNotificationPosted 方法获取数据,但我无法在 StatusBarNotification 对象中找到路线数据...
有没有人有关于如何实现这一目标的解决方案或更好的想法
最佳答案
您可以实现 NotificationListenerService 以检索谷歌 map 路线方向的内容。不幸的是 Maps 没有使用 StatusBarNotification 中的公共(public)属性。然而, map 使用 RemoteViews
来显示内容。
您可以通过广播将这些数据发送到 Activity ,并最终将内容添加到现有 View 中:
RemoteViews remoteView = intent.getParcelableExtra(id);
if (remoteView != null) {
ViewGroup frame = (ViewGroup) findViewById(R.id.layout_navi);
frame.removeAllViews();
View newView = remoteView.apply(getApplicationContext(), frame);
newView.setBackgroundColor(Color.TRANSPARENT);
frame.addView(newView);
}