如何给予支持GPS选项 [英] How to give option for enable GPS

查看:282
本文介绍了如何给予支持GPS选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示开启GPS对话框在GPS关闭。

I want to show dialog box for turn on GPS when GPS is disable .

在这里输入的形象描述

查看图像。当我点击YES,那么应该会自动在我的GPS开启无需进入设置。

See the image. When i click on YES then should be automatically turn on my GPS without going into setting.

那么,怎样才能使我通过选择YES选项GPS?

So , how can i enable GPS by select YES option ?

推荐答案

这是谷歌的一部分,发挥服务API 7.0以来名为 SettingsApi

This is part of Google play service api since 7.0 called SettingsApi.

位置设置 - 尽管 FusedLocationProviderApi 结合多个传感器,给你最佳的位置,您的应用程序接收仍是定位的精度在很大程度上取决于设备上启用的设置(GPS,WIFI,飞行模式等)。使用新的 SettingsApi 类,你可以带其中最多显示一触式控制让用户无需离开您的应用程序更改其设置的位置设置对话框。

Location settings - While the FusedLocationProviderApi combines multiple sensors to give you the optimal location, the accuracy of the location your app receives still depends greatly on the settings enabled on the device (GPS, wifi, airplane mode, and others). Using the new SettingsApi class, you can bring up a Location Settings dialog which displays a one-touch control for users to change their settings without leaving your app.

要使用这个API,首先创建支持至少 LocationServices.API A GoogleApiClient。然后,客户端连接到谷歌Play服务:

To use this API, first create a GoogleApiClient which supports at least LocationServices.API. Then connect the client to Google Play services:

mGoogleApiClient = new GoogleApiClient.Builder(context)
     .addApi(LocationServices.API)
     .addConnectionCallbacks(this)
     .addOnConnectionFailedListener(this)
     .build()
 ...
 mGoogleApiClient.connect();

然后创建一个 LocationSettingsRequest.Builder 并添加所有的LocationRequests的该应用程序将使用:

Then create a LocationSettingsRequest.Builder and add all of the LocationRequests that the app will be using:

LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
     .addLocationRequest(mLocationRequestHighAccuracy)
     .addLocationRequest(mLocationRequestBalancedPowerAccuracy);

有关下一步请点击这里:的https://developers.google.com/android/reference/com/google/android/gms/location/SettingsApi

For next steps please check here: https://developers.google.com/android/reference/com/google/android/gms/location/SettingsApi

重要:如果状态code为RESOLUTION_REQUIRED,客户端可以调用startResolutionForResult(活动,int)以弹出一个对话框,要求用户修改的位置设置,以满足这些要求的权限对话的结果将通过的onActivityResult(INT,INT,意图)返回。如果客户有兴趣哪个位置提供商提供,它可以通过调用检索的意图LocationSettingsStates fromIntent(意向)

IMPORTANT: If the status code is RESOLUTION_REQUIRED, the client can call startResolutionForResult(Activity, int) to bring up a dialog, asking for user's permission to modify the location settings to satisfy those requests. The result of the dialog will be returned via onActivityResult(int, int, Intent). If the client is interested in which location providers are available, it can retrieve a LocationSettingsStates from the Intent by calling fromIntent(Intent)

另外,请参阅本官方回购: https://github.com/ GOOGLEMAPS / Android的样本/树/主/ ApiDemos
如果你想在运行时间授予对API 23(Android版M)的权限。

Also please refer to this official repo: https://github.com/googlemaps/android-samples/tree/master/ApiDemos if you want to grant the permission on API 23(Android M) at the running time.

这篇关于如何给予支持GPS选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆