以编程方式关闭GPS

Nom*_*man 5 gps android

我有什么: 目前我的应用程序通过GPS提供位置.

我想要的是: Gps在我退出应用程序后自动关闭.因为它一直在告诉我一次又一次的位置看起来很奇怪而且gps消耗了很多电池.

Kar*_*iya 10

看看上面的评论线程似乎可以以编程方式关闭GPS(但只能看到12个Upvotes)

但是,如果您以编程方式从应用程序关闭GPS,如果其他应用程序使用GPS服务怎么办?

解决方案会像

打开Settingsandroid然后告诉用户在退出应用程序时关闭GPS ...

为此您可以这样做:

Intent i = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(i);
Run Code Online (Sandbox Code Playgroud)

要么

你可以试试

locationManager.removeUpdates(myLocationListener); 
locationManager = null;
Run Code Online (Sandbox Code Playgroud)

此关闭此应用程序的gps,但仍可供其他应用程序使用.