Lockscreen counter and text on Windows Phone 8

Tags: Windows Phone 8, WP8

 

Time now kind of follow-up on my article about dynamic lock screen.

Not only you can set the background, but your app can also provide some information to the user (If the user added it on the lock screen)

 

The two kind of information you can show on lock screen are a counter and a text. Basically, it is a dispatch of the text/counter of your primary tile information.

Setting things up

As always with Windows Phone family, you have some capabilities to add.

It is not available on the manifest editor, so we’ll have to go by hand on the XML file.

In Visual Studio, load the manifest as an XML file (Right click, “Open with” and select XML Editor) and, after the <Tokens> tag, add the following line(s) :

<Extensions>
      <Extension ExtensionName="LockScreen_Notification_IconCount" ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default" />
      <Extension ExtensionName="LockScreen_Notification_TextField" ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default" />
</Extensions>
The first line is the “Show counter” capability. The second is “Show text” capability. Depending on your app, you can only show counter or text or both.

 

Now, time to add the icon that will appear for your app counter on the lock screen. In <Token><PrimaryToken> you have a DeviceLockImageURI tag: That is where you will set the image. Example :

<DeviceLockImageURI IsRelative="true" IsResource="false">Assets\WinLogo.png</DeviceLockImageURI>

 

Now you’re ready !

Setting app on lock screen

Let’s make the user work a little bit. You can’t set yourself your app on lock screen.

To add your app the user must go to Settings/Lock Screen and add your app for counter :

   

And text :

  

 

Set counter and text

Hard to make it easier. Just update your main tile :

ShellTile.ActiveTiles.First().Update(new FlipTileData { WideBackContent = “Hello World!”, Count = 55 });

Now if you lock your device you should see this :

Updating with backgroundtask

 

Of course a backgroundtask can update the lock screen data. Just add a background task to your project and update it in the OnInvoke method. example :

protected override void OnInvoke(ScheduledTask task)
{
  var random = new Random();

  ShellTile.ActiveTiles.First().Update(new FlipTileData { WideBackContent = "Modified by background task", Count = random.Next(0,99) });

  NotifyComplete();
}

Just start your background task and you’ll see your lock screen getting updated.

Sample

 

I made a small sample app that update its lock screen information by pressing a button, or by launching a background task.

The sample is here

Comments powered by Disqus