编程语言
首页 > 编程语言> > android – 以编程方式启用位置模式高精度或省电,无需用户访问设置

android – 以编程方式启用位置模式高精度或省电,无需用户访问设置

作者:互联网

为什么我这样问:(也是在应用程序中尝试它的原因)

当我们在Lollipop中使用Google地图时会发生这种情况.即使位置已禁用,也会在用户从地图应用输入后以高精度模式启用该位置,而无需访问“设置”.

可以实现类似的功能以启用蓝牙,其中操作在我的应用程序中启动;用户需要做出选择,但用户不会重定向到“设置”,使用:

startActivity(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE));

这可以在BluetoothAdapter找到,现在我们知道没有LocationAdapter,所以我看了gms->LocationServices左右,基本上几乎所有东西都在Location API references,android.location.LocationManager下,但似乎没有像ACTION_REQUEST_ENABLE那样可用.

希望有相同的其他方法,更多人尝试过.

请注意:
context.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));不是这样的.

解决方法:

更新3:

Prompt the user to change location settings
作为@patrickandroid,在评论中提到,第二次更新的链接已被破坏

GoogleSamples; android Location and options – for code reference.

更新2:

GoogleSamples; – for code reference.

This sample builds on the LocationUpdates sample included in this
repo, and allows the user to update the device’s location settings
using a location dialog.

Uses the SettingsApi to ensure that the device’s system settings are
properly configured for the app’s location needs.

更新1:

Google Play services, Version 7.0 (March 2015) released…

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.

使用public interface SettingsApi

  • Determine if the relevant system settings are enabled on the device to carry out the desired location request.
  • Optionally, invoke a dialog that allows the user to enable the necessary location settings with a single tap.

离开前一部分以供参考:
更新/应答
对于每个寻找此答案的人,Google Play Services 7.0
它添加了用于检测地点和连接到附近设备的API,改进了移动广告,健身数据,位置设置等

In Google Play services 7.0, we’re introducing a standard mechanism to
check that the necessary location settings are enabled for a given
LocationRequest to succeed. If there are possible improvements, you
can display a one touch control for the user to change their settings
without leaving your app.

exactly this

This API provides a great opportunity to make for a much better user
experience, particularly if location information is critical to the
user experience of your app such as was the case with Google Maps when
they integrated the Location Settings dialog and saw a dramatic
increase in the number of users in a good location state.

资料来源:Android developers blog: Google Play services 7.0 – Places Everyone!

SDK Coming Soon!
We will be rolling out Google Play services 7.0 over
the next few days. Expect an update to this blog post, published
documentation, and the availability of the SDK once the rollout is
completed.

将在实施后更新程序化的l-o-c

标签:android-settings,android,google-play-services,android-5-0-lollipop,android-locat
来源: https://codeday.me/bug/20190916/1808550.html