Skip to content Skip to sidebar Skip to footer

Turn On Gps Like Gps On/off Widget

I know that you can't turn on GPS in your application without going to system preferences. But i've downloaded GPS on/off widget and this widget do the job. I've decompiled the apk

Solution 1:

Use the following function

buildAlertMessageNoGps() and launchGPSOptions()

to achieve your goal .

see The Link

Solution 2:

You can look up the source code if he posted it. Sometimes people host their code on GIT and you can browse their entire project. Specifically unless you're familiar with decompiling code using dalvik.. then that is a tricky route.

If you want to toggle the GPS, just have your widget activate an activity that toggles the GPS via passing the state of the widget to the activity via an intent. Then have your activity parse this and then close itself.

However; I would prefer to do it through a service, which is an activity without a UI. This service can be launched with your app and when a particular broadcast is received, then execute some function, which would be triggered via your widget.

Specifically you'd need to look into one type of broadcast listening. There is the XML based intent filter which will IMMEDIATELY send those particular broadcasts to your app, which can be handled accordingly.

For instance, say your widget is a toggle button with a title. When you toggle the button have you widget code send a broadcast with an intent to your service with the state of the toggle button. Then in the service, you would control the state of the GPS or any other component on the phone.

Post a Comment for "Turn On Gps Like Gps On/off Widget"