• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Can not get acceleration at screen OFF

miyazaki99

Lurker
Jul 1, 2013
5
1
I make Pedometer app that run in the background.
But I can not get acceleration at Screen OFF in GalaxyS3.
I wanna get acceleration even if device is Screen off.

I tried the following wakelock

 ・PARTIAL_WAKE_LOCK
 ・SCREEN_DIM_WAKE_LOCK
 ・SCREEN_BRIGHT_WAKE_LOCK
 ・FULL_WAKE_LOCK

But,If user turn OFF the screen,the CPU of the device stops.
If, you know when I come Action, Could you tell us.
 
i have a feeling i heard something in a podcast the other night about user apps not being able to access the accelerometer while the display is off (on stock samsung anyway). They were talking about how samsung's s-health app is ok because it can use the accelerometer as a pedometer in the background.
I could be wrong here though :beer:
 
Upvote 0
i have a feeling i heard something in a podcast the other night about user apps not being able to access the accelerometer while the display is off (on stock samsung anyway). They were talking about how samsung's s-health app is ok because it can use the accelerometer as a pedometer in the background.
I could be wrong here though :beer:
----------------
Thank you, funkylogik.

I think samsung's s-health app that use their Private API.
If it is fact,I can't get acceleration at screen OFF.

But,This app run at Screen Off.I can't understand this mechanism

Runtastic Pedometer
https://play.google.com/store/apps/details?id=com.runtastic.android.pedometer.lite
 
Upvote 0
Welcome to our AndroidForums, miyazaki99.

Not sure what issues you might be having, but I'll try to give you a few tips that might help.

Re. the Runtastic Pedometer app cited above, it uses these permissions:

package: com.runtastic.android.pedometer.lite
uses-permission: android.permission.ACCESS_COARSE_LOCATION
uses-permission: android.permission.INTERNET
uses-permission: android.permission.WRITE_EXTERNAL_STORAGE
uses-permission: com.android.vending.CHECK_LICENSE
uses-permission: android.permission.ACCESS_NETWORK_STATE
uses-permission: android.permission.READ_PHONE_STATE
uses-permission: android.permission.WAKE_LOCK

and the Play Market's Permissions tab does show this at the bottom which is certainly due to use of the above WAKE_LOCK:

AFFECTS BATTERY

PREVENT DEVICE FROM SLEEPING
Allows the app to prevent the device from going to sleep.

Here's simple code that I've used before (it's been a long while, though ;)):

[HIGH] // wakelock-related variables
//
static Boolean wakelock_acquired = false;
public static PowerManager powermanager = null;
public static PowerManager.WakeLock wakelock = null;

// initialize our powermanager and wakelock variables
//
powermanager = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakelock = powermanager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "YourAppName");

wakelock.acquire(); // keep the CPU alive![/HIGH]

Also, stackoverflow.com is a great resource for your Android questions (these are the first three results of a Google search using "android wakelock tutorial"):

How to get an Android WakeLock to work? - Stack Overflow

How can I keep my Android service running when the screen is turned off? - Stack Overflow

and this site is awesome, too:

Using Android Wakelock – Staying up all night long | vogella blog

Using the Log method to record some debugging messages I find is always helpful to record events in key places and then view them via a logcat or from the Eclipse IDE's logcat viewer.

Best of luck and I hope this helps!

:)
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones