简体   繁体   English

打开位置 (GPS) 的操作/意图是什么

[英]What is the Action/Intent to turn ON Location (GPS)

I would like to know the Intent command for Turning ON GPS automatically.我想知道自动打开GPSIntent命令。 I'm developing an Android app, and would like to enable the GPS without navigating to the settings page (Something similar to UBER).我正在开发一个 Android 应用程序,并希望在不导航到设置页面的情况下启用GPS (类似于 UBER)。 I'm looking for the Action/Intent that would trigger the LOCATION_ENABLE settings.我正在寻找会触发 LOCATION_ENABLE 设置的操作/意图。

EX: android.settings.LOCATION_SOURCE_SETTINGS_ENABLE (Something similar to This)例如:android.settings.LOCATION_SOURCE_SETTINGS_ENABLE(类似于此)

You can not enable user's location automatically but you need to request to users if they want to grant location permission to your app.不能自动启用用户的位置,但您需要向用户请求他们是否要向您的应用授予位置权限。

You will display a dialog to user explaining why do you need permission and depending upon user's interest they can enable or disable it.您将向用户显示一个对话框,解释您为什么需要许可,并根据用户的兴趣启用或禁用它。

For how to request location permission, please have a look at this question有关如何请求位置许可,请查看问题

Update:更新:

To open native GPS Settings you can use Settings.ACTION_LOCATION_SOURCE_SETTINGS action like below:要打开本机 GPS 设置,您可以使用Settings.ACTION_LOCATION_SOURCE_SETTINGS操作,如下所示:

final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);

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

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