Prashant Kadam
Prashant Kadam

Reputation: 551

how to start and Stop GPS by using code in Android

i want enable GPS for 30sec when my application start (when oncreate() method calls ). and after 30 sec it turn to disable mode.

Upvotes: 2

Views: 1055

Answers (2)

kannappan
kannappan

Reputation: 2250

try this code

locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);      
    locationManager.requestLocationUpdates(
            LocationManager.NETWORK_PROVIDER,
            1,
            0,
            myLocationListener
    );

Upvotes: 0

Hussain
Hussain

Reputation: 5562

Try this code,

 LocationManager locationManager =(LocationManager) getSystemService(Context.LOCATION_SERVICE);
 locationManager.requestLocationUpdates(
                LocationManager.GPS_PROVIDER, WLConstants.DELAY_HOUR, gpsl
                        .getMinDistance(), gpsl);

and to stop the GPS try

locationManager.removeUpdates(gpsl);

Give this after u complete ur time period.

Upvotes: 8

Related Questions