0

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 to find how the programmer have done the job with no success, dex files doen't show the code but functions and informations. Idea on how did he does that ?

1
  • hum; i've never paid attention to this, i've marked accepted answers in many of topics now :)
    – Pachanka
    Jan 14, 2011 at 22:46

2 Answers 2

2

Use the following function

buildAlertMessageNoGps() and launchGPSOptions()

to achieve your goal .

see The Link

1
  • launchGPSOptions open Security tab, but not Location Oct 22, 2013 at 17:48
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.