0

Is it possible to retrieve whether there is any current navigation running in google maps or not? Suppose my app launches google maps,but i don't to launch if google navigation is in active state. Can we get this state..?

Thanks!!

user2536783
  • 95
  • 1
  • 2
  • Maybe [ths](http://stackoverflow.com/questions/4212992/how-can-i-check-if-an-app-running-in-android) would help? If the application is running, most likely it's active, otherwise the OS would close it out. – Andy Oct 19 '15 at 17:54
  • Hi Andy, Actually i don't want to check whether google maps app are active or not, i am particularly concerned about Navigation activity in google maps. – user2536783 Oct 20 '15 at 07:01
  • 1
    you got the answer ? i am also looking for the same. – Shivanshu Verma Mar 13 '21 at 08:14

1 Answers1

1

What you're looking for is a bit tricky and depends heavily on another application's behavior. There are 2 different approaches comming to my mind without any guarantee:))

  1. Acquire Notification Access permission and check if Google Maps is showing any notification related to navigation or not (which is a little bit sensitive asking user giving you this permission and may not work if user had prevented the Google Maps from sending notifications, but who does that?) You can take a look at this How to read all the coming notifications in android

  2. Acquire Accessibility Permission and record user's behavior all the time, and when you've seen google maps in current activity, set a flag telling you that navigation was running or not (this permission is very sensitive and I don't suggest it also I guess it takes more effort) https://developer.android.com/guide/topics/ui/accessibility/service

Also, you might be able to do something using App Usage permission but I can't think about any tricky solutions using this. You can also check for some broadcasts that Maps might send while starting/ending navigation, but I don't think it does.

Finally, I'm not sure if Google Play is fine with what you want to do, I guess checking another application's state is not acceptable in most cases.

Amin
  • 3,056
  • 4
  • 23
  • 34