2

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

2 Answers 2

8

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.

0
try this code

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

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.