找出是否省电模式启用 - Android SDK中 [英] find out if power saving mode enabled - Android SDK

查看:100
本文介绍了找出是否省电模式启用 - Android SDK中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android上运行的应用程序,只使用一个web视图来显示移动Web应用程序,并在某些时候使用设备的GPS来获得自己的位置。

I have an app running on Android that uses only a webview to display a mobile web-application and at some point uses the device's GPS to obtain their position.

我有一个自定义ChromeWebClient等,并获得自己的位置很好,除了在设备上,其中节电模式已启用? 反正在SDK / API,对我来说,能够确定用户是否这使,并相应地指导他们? 我找不到任何的文档,所以我假设没有,但值得一试,

I have a custom ChromeWebClient etc and it obtains their position nicely except for on devices where the Power Saving Mode is enabled? Is there anyway in the SDK/API for me to be able to determine if the user has this enabled and to advise them accordingly? I can't find anything in the docs so i am assuming not but worth a shot,

干杯,

推荐答案

穿筘的意见后

在我的经验三星,以及宏达电,是修改Android操作系统,在大多数联合国predictable方式的厂家之一。他们增加新的功能和模式,如4G切换小部件发射和省电模式。他们修改的SDK方法权限要求,即蓝牙三星设备您的应用程序需要有和额外的 android.permission.BLUETOOTH 权限进行切换,而普通的Andr​​oid只需要 android.permission.BLUETOOTH_ADMIN 。还有更多。

In my experience Samsung, as well as HTC, is one of the manufacturers that modify Android OS in most unpredictable ways. They add new functions and modes, like 4G switching launcher widgets and "power saving mode". They modify permission requirements for documented SDK methods, i.e. to switch on bluetooth on a Samsung device your app needs to have and additional android.permission.BLUETOOTH permission, while stock Android only needs android.permission.BLUETOOTH_ADMIN. And there's more.

长话短说,因为@RaghavSood指出,省电模式是不是一个正式的AOSP的功能,也没有办法通过官方SDK检测到它。有一种可能,你如何解决它虽然方式。我相信这是最有可能是您的应用程序行为不端在省电模式,因为这种模式下关闭GPS。您可以确认通过配置省电模式设置来禁用GPS禁用(不能词组这更好的,抱歉) - <一href="http://www.techrepublic.com/blog/tablets/let-power-saving-mode-keep-your-battery-from-draining-too-quickly/1334"相对=nofollow>从谷歌与步骤第一个环节。然后测试该应用程序。它的工作原理?如果是,那么你已经rootcaused问题,现在你的工作就是让用户知道你的程序将不无GPS运行。你可以把一些code到你的应用程序来检测,如果GPS的服务已启用的显示一个警告对话框,如果事实并非如此。在code。在您的活动可以是这个样子:

Long story short, as @RaghavSood pointed out, "power saving mode" is not an official AOSP feature and there are no ways to detect it via official SDK. There is a possible way how you can work around it though. I believe it is most likely that your app misbehaves in power saving mode because this mode turns off GPS. You can confirm that by configuring power saving mode in settings to disable GPS disabling(can't phrase this better, sorry) - first link from google with steps. Then test the app. Does it work? If yes, then you've rootcaused the problem and now your job is to let the user know that your app won't run without GPS. You can put some code into your app to detect if GPS service is enabled an show an alert dialog if it isn't. The code in your activity can look something like this:

LocationManager lm = getSystemService(Context.LOCATION_SERVICE);
if(!lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
    //Show a notification prompting user to switch on GPS.
}

您可以更加精细,使您的应用程序检测设备制造商,以显示自定义消息上的所有三星设备。

You can be even more elaborate and make your app detect device manufacturer to show a custom message on all Samsung devices.

这篇关于找出是否省电模式启用 - Android SDK中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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