我想在我的应用程序启动时启用GPS 30秒(当oncreate()方法调用时)。 30秒后转为禁用模式。
答案 0 :(得分:8)
试试这段代码,
LocationManager locationManager =(LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, WLConstants.DELAY_HOUR, gpsl
.getMinDistance(), gpsl);
并停止GPS尝试
locationManager.removeUpdates(gpsl);
在你完成你的时间后给出这个。
答案 1 :(得分:0)
try this code
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
1,
0,
myLocationListener
);