WP7dev

Windows Phone 7 development tips

Tag Archives: featured app

Updating application tile without notifications

Updating the Application Tile is something very appreciated on Windows Phone 7, by users but also by Microsoft. Doing this using notifications can be quite a hassle as you need to write a server side application sending notifications to the phone, but if you need a simple tile update, Microsoft also added the ShellTileSchedule class which provides an easy way to handle this.

Exemple usage, this call is usually made in App.xaml.cs, in App() constructor :


ShellTileSchedule shellTileSchedule = new ShellTileSchedule();

shellTileSchedule.Recurrence = UpdateRecurrence.Interval;

shellTileSchedule.Interval = UpdateInterval.EveryHour;

shellTileSchedule.MaxUpdateCount = 168;

shellTileSchedule.StartTime = DateTime.Now;

shellTileSchedule.RemoteImageUri = new Uri(@”http://website.com/wp7icon.png”);

shellTileSchedule.Start();


Recurrence is used to set update recurrence : either once (Onetime) or at each interval of time (Interval).

Interval : update interval, only four values are supported : EveryHour, EveryDay, EveryWeek, EveryMonth

MaxUpdateCount : optional, you can set a max number of updates, if none is set, the updater will run indefinitely

StartTime : when will the schedule start

RemoteImageUri : image Uri, must be a 173×173 PNG file. Using transparency is allowed, and very advised (Microsoft loves when you use the user accent color)

Detecting connection loss / status on Windows phone 7

Knowing the status of the device connection can be very useful, displaying an error when trying to access something on the internet when the device has no connection is good practice. This is one of the points Microsoft loves to look at, especially when selecting featured applications.

There are two ways to handle this :

First is to use NetworkChange class, for example, in your App.xaml.cs constructor :

App.xaml.cs :


public App()

{

    // Standard App() content

    NetworkChange.NetworkAddressChanged += new  

        NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged);

}

void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)

{

    if (Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType ==

    NetworkInterfaceType.None)

        Deployment.Current.Dispatcher.BeginInvoke(

            () =>

            {

                MessageBox.Show(StringLibrary.General_NetworkError);

            });

}


Or, check directly where you need to use the connection :


NetworkInterfaceType type = NetworkInterface.NetworkInterfaceType;

if (type == NetworkInterfaceType.None)

{

    // Handle error

}


This can also be used to determine what connection type is being used, simply compare NetworkInterface.NetworkInterfaceType to the possible values of NetworkInterfaceType enum.

Be very careful when using this, as when in bad cellular cover, this call can take up to 20s.