以编程方式启用位置模式高精度或省电,无需用户访问设置 [英] Enabling Location mode High Accuracy or Battery saving, programmatically, without user needing to visit Settings

查看:329
本文介绍了以编程方式启用位置模式高精度或省电,无需用户访问设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(也是在应用程序中试用它的原因)

>当我们使用 Google地图中的棒棒糖时,发生即使位置已停用,它在用户从地图应用输入后以高精确度模式打开,而无需访问设置。



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

startActivity(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)); code>



可以在 BluetoothAdapter ,现在我们知道没有LocationAdapter,所以我环视 gms-> LocationServices ,基本上几乎所有 Location API references android.location.LocationManager ,但看起来并不像 ACTION_REQUEST_ENABLE 可用。



希望还有其他一些相同的方法,并且有更多的人尝试过。



请注意:

context.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); 不能像那样工作。

GoogleSamples; LocationSettings - 用于代码参考。 本示例基于此包含的LocationUpdates示例
repo,并允许用户使用位置对话框更新设备的位置设置



使用SettingsApi确保设备的系统设置




















$ b

Google Play服务7.0版(2015年3月)发布...


位置设置 - 虽然FusedLocationProviderApi结合了多个传感器来为您提供最佳位置,但应用程序收到的
位置的准确性仍大大取决于设置
在设备上启用(GPS,wi fi,飞行模式等)。使用
新的SettingsApi类,您可以调出一个位置设置对话框
,它显示一键控制,用户可以在不离开您的应用程序的情况下更改其设置


使用 public interface SettingsApi



  • 确定如果在设备上启用了相关的系统设置以执行所需的位置请求。
  • 或者,调用一个对话框,允许用户通过一次点击启用必要的位置设置。









将以上部分留作参考:

更新/回答

对于每个寻找此答案的人, Google Play Services 7.0

它添加了用于检测Plac的API es和连接到附近的设备,改善移动广告,健身数据,位置设置等等


$ b


在Google Play服务7.0中,重新引入标准机制到
,检查给定的
LocationRequest成功启用了必要的位置设置。如果有可能的改进,您
可以显示一个单触控制,用户可以在不离开您的应用程序的情况下更改其设置

src =https://i.stack.imgur.com/81TfP.pngalt =正是这个>



这个API提供了一个很好的机会一个更好的用户
体验,特别是如果位置信息对您的应用的
用户体验至关重要,例如Google地图的情况是
,他们将位置设置对话框集成并看到戏剧性

来源: Android开发者博客:Google Play服务7.0 - 将所有人!


SDK即将推出!

我们将推出Google Play服务7 .0未来几天将超过
。预计此博客文章的更新,发布
文档以及完成部署后的SDK的可用性。


会在执行完毕后更新程序化loc。

Why i ask this:(also the reason for trying it in an app)

It happens when we use Google Maps in Lollipop. Even if the Location is disabled, it is turned on, in high accuracy mode after user's input from the Maps app, without having to visit Settings.

A similar functionality can be achieved for enabling Bluetooth, where the action is initiated in my app; user needs to make a choice but user is not redirected to Settings, using:

startActivity(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE));

which could be found on BluetoothAdapter, now we know there is no LocationAdapter, so i looked around gms->LocationServices, basically almost everything under Location API references, android.location.LocationManager but doesn't seem anything like ACTION_REQUEST_ENABLE is available as yet.

Hope there is some other method for the same, and more people have tried it.

Please note:
context.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); does not work like that.

解决方案

UPDATE 2:

GoogleSamples; LocationSettings - 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.


UPDATE 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.

Using the 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.



Leaving the previous part for reference:
Update/Answer
For everybody looking for this answer, Google Play Services 7.0
It Adds APIs For Detecting Places And Connecting To Nearby Devices, Improves On Mobile Ads, Fitness Data, Location Settings, And More

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.

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.

Source: 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.

will update the programmatic l-o-c after implementation

这篇关于以编程方式启用位置模式高精度或省电,无需用户访问设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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