简体   繁体   English

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

[英]How do i turn off GPS Location automatically after certain time if it is not used?

Actually i used my distributors and retailers GPS location in my app when they start their meeting and GPS will not turn off until they do not end their meeting as i have to take their end meeting location . 实际上,当他们开始开会时,我在我的分销商和零售商中使用了GPS定位,而GPS直到他们没有结束会议时才会关闭,因为我必须要结束会议。 But this cause a battery problem in their phones . 但这会导致手机中出现电池问题。 Is there any way to turn off GPS Automatically between their start meeting and End meeting? 有什么方法可以在开始会议和结束会议之间自动关闭GPS?

I don't think that it is now possible to programmatically turn GPS ON/OFF. 我认为现在无法以编程方式打开/关闭GPS。 This feature was available in earlier android versions, but i think now google has stopped it. 此功能在较早的android版本中可用,但我认为现在google已将其停止。 Instead, you can direct the user to GPS settings page so that the user can himself make the choice whether he wants to expose his location or not. 相反,您可以将用户定向到GPS设置页面,以便用户自己选择是否要公开其位置。 You can do this by calling: 您可以通过致电:

startActivity(context, new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); startActivity(上下文,新的Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));

A lot of people these days are skeptical regarding sharing their location, that's why the consent of users is mandatory for sending GPS location. 如今,许多人对于共享其位置表示怀疑,这就是为什么要发送GPS位置必须征得用户同意。

You can use this 你可以用这个

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);
}}

call this when you want to disable gps or enable it when you required, more you can find from How can I enable or disable the GPS programmatically on Android? 如果要禁用gps或在需要时启用它,请调用此函数,更多信息请参见如何在Android上以编程方式启用或禁用GPS?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM