×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Sep 2013
    Posts
    4

    Sensors while screen off

    Hi

    I'm developing an app where I will need access to gyroscope while the screen is off. A lot like a run-tracking app, but not relying on GPS but gyroscope. But when the phone is off the sensors API is unavailable according to http://msdn.microsoft.com/en-us/libr...05%29.aspx/css

    Is there any way to work arround this? I'm willing to use whatever third-party libraries that might help.

    Best regards,
    Martin

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2013
    Location
    Dublin, Ireland
    Posts
    475

    Re: Sensors while screen off

    Actually, those docs refer to a Background Agent, which is different from your app (which is considered a Foreground app).

    Normally, when a user locks their phone, your app is suspended to save battery life. If you wish to ignore this and have your app keep running while the phone is locked, use UserIdleDetectionMode. The official docs have a great overview...

    http://msdn.microsoft.com/en-us/libr...v=vs.105).aspx

  3. #3
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    422

    Re: Sensors while screen off

    A scheduled Task would not work for your App anyway as by it's nature it only runs in fixed intervals of 30 minutes for 15 seconds maximum. There are two ways to approach your problem:
    1.) Make your App run under the lock screen, see [http://developer.nokia.com/Community...poldid=183830& here]
    2.) Make your full App run in the background, see [http://msdn.microsoft.com/en-us/libr...v=vs.105).aspx here]. I don't know if the scope of your App will allow it to fall under the exception in certification requirements as a location tracking App

    Are you by chance trying to do a Step Counter?

    PS: Theo was faster

  4. #4
    Registered User
    Join Date
    Sep 2013
    Posts
    4

    Re: Sensors while screen off

    We've actually tried that, and you're absolutely right - this way we can stop the screen from timing out, however it'll consume a lot of power and it's very likely that a lot of interresting stuff will happen with the device in the pocket Also, if the user presses the power switch of the phone the app can't use sensors API anymore

  5. #5
    Nokia Developer Champion
    Join Date
    Feb 2013
    Location
    Dublin, Ireland
    Posts
    475

    Re: Sensors while screen off

    The first option that SB Dev mentions is the best and only real practical solution.

    - Neil

  6. #6
    Registered User
    Join Date
    Sep 2013
    Posts
    4

    Re: Sensors while screen off

    We've just tried the sample and yes, the music is playing under the lock screen, but we made an instance of gyroscope that detects a shake of the phone and stops the mediaelement on the shake. This works while the phone is on, but when the phone is off and the music is still playing fine, the gyroscope dosn't detect the shake

  7. #7
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    422

    Re: Sensors while screen off

    What are you seeing in the Debugger if you try this. Are there no more Events with readings from the Gyroscope? I'd have guessed that under the lock screen the App should continue to work as usual but perhaps that isn't true, looking at your findings so far.

  8. #8
    Nokia Developer Moderator
    Join Date
    Feb 2011
    Location
    Portugal
    Posts
    918

    Re: Sensors while screen off

    Quote Originally Posted by developroc View Post
    We've just tried the sample and yes, the music is playing under the lock screen, but we made an instance of gyroscope that detects a shake of the phone and stops the mediaelement on the shake. This works while the phone is on, but when the phone is off and the music is still playing fine, the gyroscope dosn't detect the shake
    Have you changed the UserIdleDetectionMode property of the app’s PhoneApplicationService object to Disabled ??

    Also I think this only works if your app was the app running when the lock screen is engaged. So basically your app must be the foreground app when the screenlock is activated. (not tested).

  9. #9
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    422

    Re: Sensors while screen off

    I can at least confirm that: yes, your App must be open (on display) when the lockscreen is engaged for it to keep running (under the lock screen).

  10. #10
    Registered User
    Join Date
    Sep 2013
    Posts
    4

    Re: Sensors while screen off

    The gyroscope event dosn't fire after the lock screen comes on. It seems that Windows Phone disables the Microsoft.Devices.Sensors API while the screen is off

Similar Threads

  1. No sensors in mobility 1.1.3?
    By Tiger54 in forum [Archived] Qt Mobility Project
    Replies: 7
    Last Post: 2011-05-16, 02:11
  2. N96+sensors (another one...)
    By aesteves in forum Mobile Java General
    Replies: 0
    Last Post: 2009-11-04, 17:18
  3. Sensors
    By kamaljaiswal in forum Symbian User Interface
    Replies: 17
    Last Post: 2008-11-21, 09:41
  4. n96 + sensors
    By psinno in forum Python
    Replies: 3
    Last Post: 2008-11-10, 00:46
  5. sensors on mobile
    By delhiris in forum Mobile Java General
    Replies: 1
    Last Post: 2007-07-20, 16:45

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •