- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
更新到 Google Play 服务 v7.0+,并基于 this sample对于 Android 中的 LocationUpdates,我使用以下代码连接到 LocationServices.SettingsApi
并检查用户是否一切正常,以便应用程序接收位置更新。
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
builder.addLocationRequest(mLocationRequest);
mLocationSettingsRequest = builder.build();
PendingResult<LocationSettingsResult> result =
LocationServices.SettingsApi.checkLocationSettings(
mLocationClient,
mLocationSettingsRequest
);
result.setResultCallback(this);
this
是以下回调:
@Override
public void onResult(LocationSettingsResult locationSettingsResult) {
final Status status = locationSettingsResult.getStatus();
Intent resolutionIntent;
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
// Everything is OK, starting request location updates
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
// Seems the user need to change setting to enable locations updates, call startResolutionForResult(Activity, REQUEST_CODE)
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
// Error, cannot retrieve location updates.
break;
}
}
SUCCESS
可以重现,只要保持 GPS 启用即可。
RESOLUTION_REQUIRED
也可以重现,只是禁用 GPS。
SETTINGS_CHANGE_UNAVAILABLE
是交易:如果用户在执行步骤 RESOLUTION_REQUIRED
时选择“NEVER”,结果将始终带有此状态。
当用户选择“从不”选项时,Google Play 服务是否有一个选项可以以编程方式重置标志?
我知道“从不”似乎是“真的,不要再问我!!!”,但我想创建一个选项以防万一如果可能的话,用户当然会改变主意。
在这种情况下,我将能够再次收到状态 RESOLUTION_REQUIRED
并要求用户在下次执行应用程序时接受 LocationUpdates。
最佳答案
LocationSettingsRequest.Builder有一个方法 setAlwaysShow改变对话框的按钮:
Always show the dialog, without the "Never" option to suppress future dialogs from this app. When this flag is set to true, the dialog will show up if the location settings do not satisfy the request, even if a user has previously chosen "Never". NOTE: Only use this method if your dialog is the result of an explicit user-initiated action that requires location to proceed. Canceling this dialog should also cancel the initiated action.
如果您调用 setAlwaysShow(true);
,则使用默认的Yes、Not now 和Never 按钮代替将只有 Yes 和 No,因此用户不会选择 Never,您将永远不会收到 SETTINGS_CHANGE_UNAVAILABLE
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
builder.addLocationRequest(mLocationRequest);
builder.setAlwaysShow(true);
mLocationSettingsRequest = builder.build();
PendingResult<LocationSettingsResult> result =
LocationServices.SettingsApi.checkLocationSettings(
mLocationClient,
mLocationSettingsRequest
);
result.setResultCallback(this);
关于android - LocationServices.SettingsApi 重置 SETTINGS_CHANGE_UNAVAILABLE 标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29861580/
当位置可用时,我想返回当前的用户位置。 这是我的代码: fusedLocationClient = LocationServices.getFusedLocationProviderClient(th
我正在尝试创建一个 GPSTracker 类,我可以从一个 fragment 运行它来获取用户的 GPS 位置。我有一个运行良好,除了它需要愚蠢的棉花糖许可支持(我知道这并不愚蠢,我实际上喜欢它,但它
我正在尝试使用使用用户位置的 android studio 构建一个 android 应用程序。我正在尝试导入 google play services LocationServices api,但它
到目前为止受影响的设备: Xperia 1 II 小米红米 Note 7 使用:为了请求位置更新,我检查了位置设置事先是足够的。如果没有,我会显示一个小文本,表示服务必须为我的功能启用。如果用户点击它
我正在尝试使用以下代码获取我的 Android 应用程序的纬度和经度。 public class MainActivity extends AppCompatActivity { privat
我的代码是: if (mGoogleApiClient == null && checkGooglePlayService()) { Log.d(Utils.TAG_DEV + TAG
有人知道使用 LocationServices.GeofencingApi 的示例吗?我发现的所有 android 地理围栏示例都使用已弃用的 LocationClient 类。据我所知,可以使用 L
我正在尝试获取用户最后已知的位置。 连接 Google API 后,我调用我的函数: @Override public void onConnected(Bundle bundle) { in
我似乎做不到GoogleApiClient从事我的项目。我正在使用 LocationServices , OnConnected即使我有 client.connect() 也没有开火在 onStart
我没有使用 LocationManager,而是使用 LocationServices 方法来获取当前的 gps 位置和位置更新。 这是代码: public void onConnected(@Nul
我正在尝试使用 GoogleAPIClient 获取实时位置更新。虽然 GoogleAPIClient 已连接但位置对象为空,并且它提示 location.getProvider() 为空。有人可以帮
我正在 Visual Studio 2017 上使用 Xamarin 创建一个 Android 应用程序。我正在尝试使用本指南(http://www.c-sharpcorner.com/blogs/f
我想实现自己的定位服务。它将基于附近接入点的 wifi 信号强度的三角测量。 我知道确定我的位置的算法,但我不知道如何将它集成到我的代码中以便我可以简单地向我的服务添加一个 LocationListe
我只是想做一个简单的“教程”应用程序来获取我手机的位置(以了解稍后如何在其他应用程序中使用它),但我就是一无所获。 我做了什么 Android 开发人员教程: 首先,我遵循了 Android 开发人员
我不明白为什么 LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,mLocationRequest,
我正在 Android 上使用 Google Play 服务位置 API,我正在尝试弄清楚如何测试 onConnectionSuspended(int Cause) 回调,该回调是 GoogleApi
我正在开发一个 Android 库,我需要删除由使用我的库的开发人员添加的播放服务依赖项。我需要用户位置最后一个位置,所以我需要使用反射,因为位置库不会直接包含在我的库中。 但是如何通过反射从构建器创
你好 Stackoverflow 社区,我是 android 的新手,正在学习如何实现基于位置的服务。 我成功地实现了一个速度计应用程序,它可以测量当前速度、总距离和总行驶时间。 现在我想添加一个额外
我已经在其他线程中阅读了该问题的解决方案,但我似乎不明白为什么它会返回 null。我使用了谷歌开发者网站提供的相同 fragment :https://developer.android.com/tr
我有一个高优先级的项目正在开发中。 我正在尝试将地理位置插入数据库,因此我找到了在线服务,不幸的是 LocationRequest 和 LocationServices.API 未解析。 我正在使用依
我是一名优秀的程序员,十分优秀!