如何使用Android中的代码启动和停止GPS

Pra*_*dam 2 android android-service android-location

我想在我的应用程序启动时启用GPS 30秒(当oncreate()方法调用时).30秒后转为禁用模式.

Hus*_*ain 8

试试这段代码,

 LocationManager locationManager =(LocationManager) getSystemService(Context.LOCATION_SERVICE);
 locationManager.requestLocationUpdates(
                LocationManager.GPS_PROVIDER, WLConstants.DELAY_HOUR, gpsl
                        .getMinDistance(), gpsl);
Run Code Online (Sandbox Code Playgroud)

并停止GPS尝试

locationManager.removeUpdates(gpsl);
Run Code Online (Sandbox Code Playgroud)

在你完成你的时间段之后给这个.