简体   繁体   中英

find out if power saving mode enabled - Android SDK

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.

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,

Cheers,

Lee

After reeding the comments

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, ie 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM