In Silverlight 8.0 there was a capability to run an application for a period of time after the user switched away to perform continuous GPS tracking for up to a few hours. With the switch to the Windows Runtime there was no direct equivalent of this. I discovered however that because there are differences with what you are allowed to do on Windows Phone versus Windows Store apps with the DeviceUseTrigger you can do something similar.
The GPS device itself doesn’t qualify for use with the trigger but you can use another sensor on the device. Since all Windows Phone devices have an Accelerometer you can use this. The documentation states that you must poll the sensor at least every 5 seconds otherwise it will kill your background process. Since GPS commonly updates once per second you are given the choice of polling with a 1-5 second interval depending on what you need. With a bit of logic you could extend this but you’d still be polling the accelerometer at least once every 5 seconds.
The GPS adaptation is simply to recreate a DeviceUseTrigger based background task – using the official code sample as a base. Then we add a Geolocator and get the position on each call of the handler which is called for each reading. In the attached sample we simply capture the position every 5 seconds and update the application tile. So you’ll need to run the app and pin it to the start page to see it at work.
In order to show the minimal code to demonstrate the technique I’ve not added any decent error handling or analytics so don’t just paste this code into a real project and use it as-is.
I’ve been working on a Windows Phone 8.1 project which has several background tasks. One of these uses the device’s sensors – using a DeviceUseTrigger. This is different to how a regular periodic task works because the task implementation creates a deferral and keeps running handling the event generated by the sensor device until it is explicitly cancelled. The task is created normally with a class implementing IBackgroundTask and runs under the context of BackgroundTaskHost.exe. Because I wanted to share some data with the other tasks as a when they run I was interested if these other IBackgroundTask implementations were also hosted in the same process. If so this means that any static instances would be shared between them. Since I couldn’t find the answer I did some testing with some additional debugging and discovered that no, they each run in a separate process.
This lead me to explore how to share data between them. There are no built in IPC classes in the Windows Runtime like MessageQueues or similar so really the only options are the LocalSettings for individual setting values and files placed in the LocalFolder for any other data. The added complication here is that you have to handle the situation where both processes may try to read/write the file at the same time. Luckily you can use a named Mutex to enforce exclusive access to the file and have the other process wait on the Mutex.
I recently got a Lumia 930 and was looking for a simple car holder/charger for it. I saw the CR-201 (which is updated from the CR-200 and advertised as compatible with the 930) and thought it would be perfect because:-
1) It has wireless charging so just pop the phone in, no fiddling with USB cables
2) It looks nice
However it doesn’t really fit the 930 and so this leads to a couple of issues – The clamp mechanism grabs the camera button, the sticky cable ties don’t stick to any material other than the plastic film they ship with and the wireless charger doesn’t deliver a charge capable of supporting charging while using the holder. No doubt this latter issue is also due to the size/positioning just not being right. Sadly it’s only after you discover these issues yourself you then find other reviewers online have encountered the same problems. So it’s going back and I’m looking for an alternative.
Last month I posted the latest “charming” helper for Windows development which is a Windows Phone (8.0 or Silverlight 8.1) ProgressRing with the same appearance as its big Windows counterpart.
Today I’ve just pushed an update to NuGet which improves the flexibility of the control by allowing you to override the Foreground colour of the rotating dots. The default is still to use the phone’s accent colour so this is what you’ll see if you don’t specify the Foreground brush explicitly. Details here:-
In Silverlight 8.x you can use the Toolkit Rating control to provide standard star rating functionality in your app. If you’re moving to a Windows Phone 8.1 App project you can’t use the Silverlight based toolkit and there isn’t a native control to replace it.
If you’ve worked with Windows Store apps you’re probably familiar with the Callisto toolkit – a set of controls for Windows Store apps that brought things like settings flyouts (prior to them being rolled into the Windows Runtime) and a rating control. You can use this control within a Phone app with one caveat. If you try to reference the NuGet package for Callisto it will tell you it contains no library for Phone apps. However if you are using a Universal project this is easy to overcome:-
- Add the Callisto NuGet package to your Windows Store app
- In your Phone project select Add Reference and browse to the packages folder in the root of your solution
- Locate Callisto.1.4.0/lib/netcore451 and select Callisto.dll
- Bingo you can now add the rating control to your phone project.
I haven’t tested all the functionality in a Phone project so it is possible there may be some items which don’t work on Phone…
Hopefully in a future update to the Callisto NuGet package it will include a dll for Phone 8.1 apps too to avoid these extra steps…
Charming Share provides a share API for Windows Phone 8.0 projects which mimics the built in support in various system apps and exposes an API which is the same as that available in Windows 8.1 and Windows Phone 8.1. Now that we have a full Sharing feature in Windows Phone 8.1 we can take advantage of this from both AppX and Silverlight 8.1 projects. But what if you need to continue using a Silverlight 8.0 project?
Well the answer is to use Charming Share as it is now smart enough to determine when it is running on an 8.1 device and defer to the system Sharing feature. To quickly illustrate here are screenshots from the same 8.0 project running on both 8.0 and 8.1:-
The eagle-eyed amongst you will notice the 8.1 list is quite sparse – this is because it’s taken from the Emulator which has no email accounts or social apps installed. But imagine Facebook etc and any other third-party apps appearing in this list.
In terms of look and feel, I don’t have any plans to change the look of the 8.0 sharing screens – these are designed to match the system as this is how the sharing features appear in Windows Phone 8.
Now that there are so many platforms to cover I’ve changed the main documentation page into a feature matrix so it is easier to compare functionality across platforms and app models
In the latest release of Charming Share which is now live on NuGet I’ve added a new Clipboard API.
For Windows Phone 8 and 8.1 Silverlight apps this wraps the existing Silverlight functionality. For Windows Phone Store 8.1 applications this provides a workaround to the lack of any Clipboard API on that platform. The library provides a Windows-style API (differing only in root namespace) to make it easier to share more code across projects.
As with the existing Silverlight model the Clipboard is “write-only” with only the user in control of pasting the contents into a TextBox. It exposes two static methods – SetContent and Clear. I haven’t yet updated the documentation on the project site but these two methods are fairly straight-forward. Unlike “big” Windows the clipboard can only store plain text (again this is familiar from the Silverlight model) so will accept data packages containing text or Uris.
In order to facilitate this functionality on non-Silverlight apps on 8.1 there is of course a gotcha. It requires a separate app to be installed and there is a small visual transition while this app handles the request. This isn’t ideal but if there are some cases where you need Clipboard it is a necessary evil and by matching the Windows Store API we have hopefully provided a clean transition should this missing feature be added in a future release.
Why would I want another app? When building this solution I though about how this add-on app could provide additional value and so it takes advantage of a number of Windows Phone 8.1 features. It doesn’t use any online services so the data you share with it never leaves the device. It’s a simple free app called “Clipboarder” and I encourage you to check it out (and provide feedback!).
Share Target: You can share text and Uris to the clipboard from other Windows Phone 8.1 apps which are Share sources.
Share Source: If you run the app from the programs list you can enter arbitrary text and either copy to the clipboard or Share with other Windows Phone 8.1 targets.