开发者

how to start and Stop GPS by using code in Android

开发者 https://www.devze.com 2023-03-14 07:02 出处:网络
i want enable GPS for 30sec when my application start (whenoncreate() m开发者_如何学JAVAethodcalls ).and after 30 sec it turn to disable mode. Try this code,

i want enable GPS for 30sec when my application start (when oncreate() m开发者_如何学JAVAethod calls ). and after 30 sec it turn to disable mode.


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.


try this code

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

精彩评论

暂无评论...
验证码 换一张
取 消