Location Tracking in Background - windows-phone-7

I am developing a windows phone app that uses users current location, I am making the app in 7 OS. My question is, Can I track the location in background, that is when the screen is locked?
I know this is a possibility in wp8 as it provides us with GeoLocator class, but can I achieve this in wp7? I am basically making a runtracker app hence I would like my app to track the location even when its in background, is it really feasible?
Your help is always appreciated!!

It is possible to keep the app running under lock screen, as it does, for example, Endomondo app.
Using Idle Detection, you can keep the app on, although screen is locked, and you can keep on tracking the location. Actually, it is not running in background, but in the foreground. Just the screen is locked. So, be careful not to drain user's battery.
You have to set the PhoneApplicationService.ApplicationIdleDetectionMode property to Disabled, for example in InitializePhoneApplication() method in App.xaml.cs:
PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Disabled;
Note that there are special certification requirements for this type of apps. Refer to section 6.3 (Apps running under a locked screen) of the following page:
Additional requirements for specific app types for Windows Phone

I got the same problem in one on my apps..
I don't think it' s feasible for wp7..
Bt if you want to do it with wp8 you can refer following link.
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj681691%28v=vs.105%29.aspx
And to know about background supported and unsupported API's http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202942%28v=vs.105%29.aspx/css

GeoCoordinateWatcher Class exists in WP7, but here is the documentation from MSDN -
This API, used for obtaining the geographic coordinates of the device,
is supported for use in background agents, but it uses a cached
location value instead of real-time data. The cached location value is
updated by the device every 15 minutes.
More Info : http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202962%28v=vs.105%29.aspx/css

Related

Is it possible to get an app to open up when entering a beacon region / within range of a beacon/ibeacon

I'm exploring the end user experience for a beacon prototype but I'm struggling to find any end-user scenarios that involve the app becoming active / opening up on the screen when within range.
I can get the app to send a notification and this is the most likely experience on both Android and iOS but does anyone know if it is possible to get the app to open up?
It's unlikely that I'd want real customers to have their experience interfered with in this way, I think it's ok if the app is already running and is open but not if it's running but not open.
Thanks
On Android this is possible. The reference app for the Android Beacon Library demonstrates how to do exactly this.
On iOS, it is not possible due to OS security restrictions. See here for details. The best you can do is send a local notification to the user when the beacon is detected, then if the user gestures to it, bring up the app.

GPS based application not running under lock screen in windows phone

I have developed a windows phone application and it works fine when it is open and running actively.
It tracks the user movements on the map and shows the position moves with push pins.
Now I want to ensure that the same application runs even the phone is locked when this app was open.
I have added the below code for it to work under lock screen. After this when I verified the app I realized it is not running when the application is locked.
Is there any other change I need to make to get this work under lock screen.Any help would be greatly appreciated.
private void initiliazesettings()
{
PhoneApplicationService.Current.UserIdleDetectionMode =
IdleDetectionMode.Disabled;
}
To have your app running under lock screen on Windows Phone 7.0/7.1/8.0, you need to set ApplicationIdleDetectionMode, not UserIdleDetectionMode. See details here.
Supossing you placed the method in the right place, that code only keeps the screen on, but doesn't make your app run in background when the lock screen is activated. Windows Phone 7 apps cannot run in background, they get tombstoned.
For Windows Phone 8 this is possible - see the sample here from MSDN.
However for Windows Phone 7/7.1 you can't do this.
You can prevent the screen from locking due to the user not interacting with it (as your code shows). However if you manually lock the screen the app will still be made dormant or tombstoned and your location code won't run.
Your only other option is to use a scheduled background task to read the location of the phone, but bear in mind that this is far from real time data (it is a cached location and you only run once every 30 minutes in the best case scenario).

WP7: Edit Screenshot While App is Backgrounding (Mango)

I have an app that I have been developing that can display sensitive user data.
When the user backgrounds the app, the OS appears to take a screenshot of the app as it was running, and displays it so when the user returns, their state is restored.
I am trying to prevent the user's information from being seen in this screenshot.
My initial idea was to display a Popup of my splash screen image, but it does not seem to render it in ApplicationDeactivated. Is there any other way you might accomplish this?
I am not sure you are analyzing this correctly. I don't see how the OS could take a screenshot of an app and use that to restore state. Also, if it was true that the OS did that, Tomb Stoning wouldn't be such a big issue in the requirements for an app in the submission process. A dev needs to handle grabbing and saving state on exit and reloading it on start-up again.
If you didn't code this tomb stoning, are you using a frameowrk that has built in support for this? You could disable the tombstoning so certain pieces of information are not stored, and in fact if this data is that sensitive you should make sure it isn't saved. But, if you save it make sure you encrypt it so nothing else could examine the saved state. Although, that shouldn't be possible on Win Phone as the OS is supposed to enforce the boundries between apps.
Received a response from Microsoft which indicates that this is not possible in the Mango SDK; it may be added into future releases of the platform.

windows phone app running in the background

Is it possible to create an app the runs in the background? If so is there any samples out there for this?
In Windows Phone OS 7.1 you can actually use Background Agents now to perform tasks in the background.
from MSDN:
Scheduled Tasks and background agents allow an application to execute
code in the background, even when the application is not running in
the foreground. The different types of Scheduled Tasks are designed
for different types of background processing scenarios and therefore
have different behaviors and constraints.
You can use a PeriodicTask or ResourceIntensiveTasks. Read more about it in the MSDN article above.
And here's some sample code for you to integrate background agents into your existing app.
Sample Code: Background Agents in Mango
An application in the foreground can continue to run when the phone screen is locked(not background but...) by setting the PhoneApplicationService.ApplicationIdleDetectionMode property. By setting up your application to run when the phone screen is locked, a user is able to access the application quickly upon unlock. However, when your application runs under a locked screen, it could consume power outside of the user's control. For this reason, your application must minimize power usage when running under a locked screen
At the moment there is no way to create application that runs in background.
True multitasking for 3rd party Windows Phone 7 apps will come as an OS upgrade later this year. However, unless the app has to absolutely run in the background (like Pandora etc.), we as developers share some responsibility in making our apps feel at home with the rest of the OS.
Windows Phone OS offers app developers chances to save state of their applications to give the end users the feeling that it never stopped running; this is essentially the same as in other mobile platforms. As your app is being deactivated/closed, you have the option to "Tombstone" your state so that your users can come back to just where they left with BackStack navigation or future launches. Channel 9 had a nice set of demos & labs around tombstoning, found here.
Hope this helps!

Track Accelerometer under lock screen

Is it possible to track the accelerometer value while under the lock screen?
I managed to write a simple application which counts from 1 up to 100 using a timer which fires an event on which I increment a counter.
But when I use register a handler for the ReadingChanged event of the accelerometer it will not be fired anymore once the screen has been locked. Even if I unlock the screen again I will have to readd my handler.
the msdn documentation tells on the one page:
http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff941090(v=vs.105).aspx
"Valid reasons to disable idle detection in Windows Phone OS 7.1 applications include ones where core functionality continues while the phone is locked (for instance, an exercise tracking app)"
but the sensor api also tells:
http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202968(v=vs.105).aspx
"The Sensor APIs cannot be used while the application is running under the lock screen. For more information, see Idle Detection for Windows Phone. The Sensor APIs also cannot be used in background agents. For more information, see Background Agents Overview for Windows Phone"
I hope they will change the api soon, because of that it is not possible to write any good sleep tracking / sport tracking applications ... :(
I was helping a guy with this a couple of days ago. He had an app that tracks GPS and accelerometer data under lock screen.
Turned out the app accelerometer data stopped tracking when under manual or auto lock screen.
There may be an issue here to be looked into.
Under lock screen it is a good idea to minimise power usage... disable all uncessary code, like ui updates. My understanding of one the motivations for idle detection and running under lockscreen being opened up during CTP was in response to a lot of feedback from developers of map/tracking apps that basically need this for their app to be of any use.
I'm not sure of the usage case where you'd want to use the accelerometer under the lock screen.
Apps typically run under the lock screen when you need them to do something when you're not interacting with the device. e.g. playing music or downloading a large file.
If you wanted accelerometer data I'd assume that the device is being held and, therefore, presumably, looked at. Given this, why would you therefore want to run under the lock screen?
That being said, if you had a good reason to do so, you should still be aware that:
when your application runs under a locked screen, it ... must minimize
power usage
(from the Marketplace Certification Requirements.)
In my understanding, reading values from sensors is not minimizing power usage.

Resources