0

I have made an android applicaiton (2.2) with GPS functionality.But I want to check GPS status in device is it turn on or turn off. But don't know how to check by programming. Please give me some advice for this question.

Thanks in advance. Edit:

Here is the code for location listener

 lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        ll = new mylocationlistener();
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
        lm.addGpsStatusListener(this);


private class mylocationlistener implements LocationListener {
        @Override
        public void onLocationChanged(Location location) {
            mLastLocationMillis = SystemClock.elapsedRealtime();
            mLastLocation = location;
        }
Reno
  • 32,851
  • 11
  • 85
  • 99
ManthanDalal
  • 1,065
  • 2
  • 20
  • 43

2 Answers2

0

I think you can find all the answers here: How can I check the current status of the GPS receiver? and here: How do I find out if the GPS of an Android device is enabled

Community
  • 1
  • 1
berni
  • 1,925
  • 1
  • 19
  • 16
  • what is a fix? in the answer that is mentioned on your link ,the guy is talking about a fix on the gps.. what does that mean? – user590849 May 19 '11 at 09:52
  • 1
    A GPS position fix is a valid GPS position returned by a device. (more at [link](http://en.wikipedia.org/wiki/Fix_%28position%29)) – berni May 19 '11 at 10:12
  • is a any permissions to be added to the android.manifest file? – user590849 May 19 '11 at 10:26
  • 1
    yes. As stated in link in my answer you should add ACCESS_FINE_LOCATION to the manifest (more at [android docs](http://developer.android.com/reference/android/Manifest.permission.html#ACCESS_FINE_LOCATION)) – berni May 19 '11 at 10:29
  • did that already when i implemented the onLocationChanged method. – user590849 May 19 '11 at 10:38
  • the method that is suggested in the link that you gave does not work. i have tried it. GPS status changed is never called. i am sitting in a building if that would make any difference. – user590849 May 19 '11 at 11:44
  • Are you using emulator? If so you will have to provide GPS fix yourself. To do this you need to do the following: 1. connect to emulator by invoking _telnet localhost 5554_ 2. send location data to it by providing latitude and longitude _geo fix -121.45356 46.51119 4392_ as described here [http://stackoverflow.com/questions/2279647/how-to-emulate-gps-location-in-the-android-emulator/5632107#5632107](http://stackoverflow.com/questions/2279647/how-to-emulate-gps-location-in-the-android-emulator/5632107#5632107) – berni May 19 '11 at 12:30
  • no i am using a device. Also the method , onlocationchanged is not being called? the gpsstatuschanged is being called, but not locationchanged? what could be going wrong? i have add code for requestlocationupdates(). – user590849 May 19 '11 at 12:36
  • You could provide the code of your implementation. Is app working fine od emulator? Especially if you provide fix from console? Remember that it could take up to couple minutes to get a fix (it depends on sky visibility). Have you tested other apps using gps position on your device? – berni May 19 '11 at 12:41
  • yes, there is the most common, google maps. it works fine on device.Also i have not tested the app on emulator with fixed co-ordinates, what could be going wrong, why is onlocationchanged not being called? – user590849 May 19 '11 at 13:03
0

1) Call addGpsStatusListener() add your listener to it.

2) In the onGpsStatusChanged() callback call the function getGpsStatus()

OR

If you are interested in Sattelite info. you can get it in the LocationListener when requesting for GPS location onStatusChanged()

Reno
  • 32,851
  • 11
  • 85
  • 99