我想在我的应用程序启动时启用 GPS 30 秒(当 oncreate() 方法调用时)。并在 30 秒后转为禁用模式。
最佳答案
试试这段代码,
LocationManager locationManager =(LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, WLConstants.DELAY_HOUR, gpsl
.getMinDistance(), gpsl);
并停止GPS尝试
locationManager.removeUpdates(gpsl);
在你完成你的时间段后给这个。
关于android - 如何在 Android 中使用代码启动和停止 GPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6410889/