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

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

问题描述

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

这种情况发生在我们在 Lollipop 中使用 Google 地图时.即使位置被禁用,它也会在用户从地图应用程序输入后以高精度模式打开,而无需访问设置.

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

startActivity(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE));

可以在

<块引用>

SDK 即将推出!
我们将推出 Google Play 服务 7.0 以上接下来的几天.期待此博客文章的更新,已发布文档,以及推出后 SDK 的可用性完成.

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

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 3:

Prompt the user to change location settings as @patrickandroid, mentioned in comments, the link from second update is broken

GoogleSamples; android Location and options - for code reference.

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


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天全站免登陆