简体   繁体   English

检测Waze或Google地图移动版中的导航结束

[英]Detecting the end of navigation in Waze or Google Maps for mobile

I want my mobile app to be triggered by the "end-of-navigation" in either Waze or the Google Maps app. 我希望我的移动应用程序由Waze或Google Maps应用程序中的“导航结束”触发。 In it's simplest form, I would like my app to do something when the user gets the "You've arrived at your destination" notification from the navigation app. 在它最简单的形式中,我希望我的应用程序在用户从导航应用程序获得“您到达目的地”通知时执行某些操作。

I realize, in Android at least, that I can start the navigation (either in Waze, or Google Maps app) by creating an intent. 我知道,至少在Android中,我可以通过创建意图来启动导航(在Waze或Google Maps应用程序中)。 Then, I can run my own proximity sensor in my app to wait for the user to arrive. 然后,我可以在我的应用程序中运行自己的接近传感器,等待用户到达。 However, I wanted something far cleaner - a situation where all that is required from the user is to have my app working in the background and then for this app to able to respond to the event of arrival directly. 但是,我想要一些更清洁的东西 - 用户需要的一切就是让我的应用程序在后台运行,然后让这个应用程序能够直接响应到达事件。

Solutions either in iOS or Android are very welcome. iOS或Android的解决方案非常受欢迎。 Hacky solutions are also very welcome. Hacky解决方案也非常受欢迎。

Thanks 谢谢

A simple solution will be to create a GeoFence just before the intent for navigation is started. 一个简单的解决方案是在启动导航意图之前创建GeoFence。 You can listen to Geofence.GEOFENCE_TRANSITION_ENTER event using an intent service running in background. 您可以使用在后台运行的意向服务来收听Geofence.GEOFENCE_TRANSITION_ENTER事件。 When this event happens you can do what ever task you need to do from the service class. 发生此事件时,您可以从服务类执行您需要执行的任务。 This same principle can be implemented in ios also: Here is a tutorial for implementing Geofence in ios http://www.raywenderlich.com/95014/geofencing-ios-swift and in android http://paulusworld.com/technical/android-geofences 同样的原则也可以在ios中实现:这是一个在ios中实现Geofence的教程http://www.raywenderlich.com/95014/geofencing-ios-swift和android http://paulusworld.com/technical/android -geofences

A super hacky thing you could do (almost don't want to post this) would be to use the NotificationListenerService and keep an eye out for the notifications from google maps or waze. 你可以做的超级hacky(几乎不想发布这个)将是使用NotificationListenerService并留意来自谷歌地图或waze的通知。

http://developer.android.com/reference/android/service/notification/NotificationListenerService.html#nestedclasses http://developer.android.com/reference/android/service/notification/NotificationListenerService.html#nestedclasses

I think it should be for public to use as long as you have the permission. 我认为只要你获得许可,就应该让公众使用。

You're going to have to think of something smart for languages, maybe reading resources from the google maps / waze apps to ensure you don't miss notifications that are not in English. 你将不得不考虑一些聪明的语言,也许从谷歌地图/ waze应用程序中读取资源,以确保你不会错过非英语的通知。

This may be viable for iOS as well: https://developer.apple.com/library/ios/documentation/CoreBluetooth/Reference/AppleNotificationCenterServiceSpecification/Specification/Specification.html I don't have personal experience with the watch Apis for iOS so you'll have to dig around there yourself. 对于iOS来说这也是可行的: https//developer.apple.com/library/ios/documentation/CoreBluetooth/Reference/AppleNotificationCenterServiceSpecification/Specification/Specification.html我对手表Apis for iOS没有个人经验所以你必须自己在那里挖掘。

The only possible solution here is to poll the active activities (foreground ones) each X seconds and act from there. 这里唯一可行的解​​决方案是每X秒轮询一次活动活动(前景活动)并从那里开始行动。 You can do it with a service and alarm. 您可以通过服务和闹钟来完成。

You can do it in the following ways: 您可以通过以下方式执行此操作:

Check current running processes: 检查当前运行的进程:

 ActivityManager manager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> processes = manager.getRunningAppProcesses();
    for (RunningAppProcessInfo process : processes) {
       if (processName.equals(process.processName)) {
           // do your thing
       }
    }

OR (less preferred) check the current foreground application: 或(不太喜欢)检查当前前台应用程序:

ActivityManager am = (ActivityManager) context
                .getSystemService(Activity.ACTIVITY_SERVICE);
        String packageName = am.getRunningTasks(1).get(0).topActivity
                .getPackageName();

In iOS i am not sure you will get a call back from google or Waze. 在iOS中,我不确定您是否会收到谷歌或Waze的回电。 best way is to use startMonitoringForRegion . 最好的方法是使用startMonitoringForRegion if you enter region(destination) your app will get a call back. 如果您输入地区(目的地),您的应用将收到回电。 if your app is not running OS will launch your application. 如果您的应用未运行,操作系统将启动您的应用程序。 hope this will help 希望这会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM