如果不使用,如何在一定时间后自动关闭GPS位置?

时间:2017-04-05 06:26:25

标签: android gps java-threads android-gps

实际上,当我们开始他们的会议时,我在我的应用程序中使用了我的经销商和零售商GPS位置,并且GPS不会关闭,直到他们不结束他们的会议,因为我必须采取他们的最终会议地点。但这会导致手机出现电池问题。有没有办法在开始会议和结束会议之间自动关闭GPS?

2 个答案:

答案 0 :(得分:0)

我认为现在无法以编程方式打开/关闭GPS。此功能在早期的Android版本中可用,但我认为现在谷歌已经停止了它。 相反,您可以将用户定向到GPS设置页面,以便用户可以自己选择是否要公开他的位置。 您可以通过以下方式执行此操作:

  

startActivity(context,new   意图(Settings.ACTION_LOCATION_SOURCE_SETTINGS));

这些天很多人对于分享他们的位置持怀疑态度,这就是为什么用户同意必须发送GPS位置。

答案 1 :(得分:0)

您可以使用此

private void turnGPSOn(){
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

if(!provider.contains("gps")){ //if gps is disabled
    final Intent poke = new Intent();
    poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider"); 
    poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
    poke.setData(Uri.parse("3")); 
    sendBroadcast(poke);
}}private void turnGPSOff(){
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

if(provider.contains("gps")){ //if gps is enabled
    final Intent poke = new Intent();
    poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
    poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
    poke.setData(Uri.parse("3")); 
    sendBroadcast(poke);
}}

当您想要禁用gps或在需要时启用它时调用此方法,您可以从How can I enable or disable the GPS programmatically on Android?找到更多