ControlUI to control GPS?

Post your questions and help other users.

Moderator: Martin

dragsterhund
Posts: 1
Joined: 05 Jan 2015 00:57

ControlUI to control GPS?

Post by dragsterhund » 05 Jan 2015 01:20

Hi guys,

I'm trying to build a flow that, when the phone is plugged in to my car charger, turns on bluetooth, activates GPS and logs the locations, and turns the volume up to maximum. Turning the bluetooth on is no problem. Apparently, to turn my GPS on, I have to root my phone, which I'd like to avoid, if I can. Would it be possible to get around direct control of the GPS state by building a set of commands using ControlUI instead? I realize that would be more complicated, but it would get around me having to root the phone.

Also, the charger in the car is just the USB cigarette lighter type. Can the device detect a type of charger? In other words, I would like this flow to run only if it's plugged into the car, and not the wall outlet at home.

Phone:
Non-rooted Galaxy S5
Android 4.4.4
Verizon

If I absolutely have to root my phone for this to work, could someone recommend a rootkit build for me?

Thanks!

User avatar
kintrupf
Posts: 257
Joined: 10 Sep 2013 08:59

Re: ControlUI to control GPS?

Post by kintrupf » 05 Jan 2015 07:29

You might want to take a look into the trigger User Activity (Experimental) with the activity In Vehicle. I use this trigger to turn on Bluetooth when I'm driving in my car with very good results. You can combine this with a condition Power Source Connected to execute the rest of your flow only when your phone is charging.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: ControlUI to control GPS?

Post by Martin » 05 Jan 2015 20:23

Hi,

Action Control UI can be used to toggle GPS. It's usually the easiest solution to first launch the nearest settings page and then press only as few buttons as required with Control UI.
A flow like this could work (depending on device language):
-trigger ...
-action Launch App: com.android.settings/.Settings$LocationSettingsActivity
-action Sleep: 1s
-action Control UI with script:

Code: Select all

click("Mode");
sleep(1000);
click("GPS only");
home();
The sleeps are required since it takes some time for Android to show the settings pages.

Regards,
Martin

angelatwork
Posts: 186
Joined: 12 Feb 2014 01:45

Re: ControlUI to control GPS?

Post by angelatwork » 09 Jan 2015 15:10

I second dragsterhund's wish! I am really interested in this subject too. I have made different flows with different triggers, but haven't found them reliable enough. Having the cig lighter as a trigger would be great, if that at all is possible! Using in vehicle is not such a good solution, in my case anyway. If you want to log your position on start, it is not anywhere near start position by the time you get your position. First the car needs to be in motion, i. e. already moving away from the position you want to log, then you have the time to connect to GPS through UI,and then the time (that can be rather long) before you get a fix on your position.
Best regards,
AngelAtwOrk

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: ControlUI to control GPS?

Post by Martin » 09 Jan 2015 15:48

Android only provides a way to distinguish between AC, USB and wireless chargers which will probably not be good enough in your case.
Maybe you could use a two step process to detect whether you are in the car or not, for example detect when power is connected, enable bluetooth, wait some seconds to see if the device connected to the car and then start the other car actions. Something like this:
-trigger Power Source: Connected
-action Set Bluetooth State: On
-action Sleep: 10s
-condition Bluetooth Device Connected: Maybach
--> true: -some actions when in car
--> false: -action Set Bluetooth State: Off

Wibbly
Posts: 418
Joined: 17 Mar 2014 09:02

Re: ControlUI to control GPS?

Post by Wibbly » 09 Jan 2015 16:05

Why is it necessary to switch GPS on/off? Android should dynamically power GPS up when an app requests it. On my phones at least, GPS usage then stops when the requesting app is closed. So I control GPS by controlling the apps that request GPS...

For in-car actions I use a NFC tag on the phone holder in combination with it being powered, but appreciate not all phones have NFC capability. I run exit-car actions when the phone has been put in 'car mode' and then external power to the phone is removed.

I can't use the Bluetooth device in the car as a condition, as it's always on so my phone would think I'm in the car when I'm in my house (as the Bluetooth range is too good)!

angelatwork
Posts: 186
Joined: 12 Feb 2014 01:45

Re: ControlUI to control GPS?

Post by angelatwork » 09 Jan 2015 19:23

On a non-rooted Android (at least Samsung, have a few different ones) no app can start GPS by itself, just tell you to do it.

When trying to minimize what you have to do, nfc is not the best option, especially if you use different cars. But thanks for your input!

Martin I will try your solution and see if it's a winner our not :-)
Best regards,
AngelAtwOrk

Wibbly
Posts: 418
Joined: 17 Mar 2014 09:02

Re: ControlUI to control GPS?

Post by Wibbly » 09 Jan 2015 20:12

Ah ok - on a stock Nexus 4 you enable GPS in the settings and it only actually fires up when apps request it. When it's not fired up it consumes (almost?) no power (even though it's enabled). So I just leave it enabled without any apparent downside.

angelatwork
Posts: 186
Joined: 12 Feb 2014 01:45

Re: ControlUI to control GPS?

Post by angelatwork » 10 Jan 2015 12:27

Ok, wibbly, are you saying that although you have enabled GPS all the time in your settings, so apps can use it when they need it does not drain the battery if you are not using it? How have you measured that? I might be in the wrong here, since my battery seems to drain? Also I admit, I am not that fond of google and others always knowing exactly where I am, out of principle :-). Not liking companies being Big Brother!
Best regards,
AngelAtwOrk

Wibbly
Posts: 418
Joined: 17 Mar 2014 09:02

Re: ControlUI to control GPS?

Post by Wibbly » 10 Jan 2015 15:34

Yes, that's what I'm saying.

If I leave the phone idle over night, battery goes down 0.5 - 0.7%/hr regardless of if GPS is set on or off

Post Reply