Windows Phone 8

App Spotlights for Windows Phone

I’m pleased to announce the availability of App Spotlights.

As a Windows Phone developer, I can tell you that one of the best gifts a developer can receive is when one of his apps is in the spotlight. First, it’s an honor from Microsoft to be selected and secondly, it has a huge impact on downloads. Currently, there is no easy way to know if an app is featured, as there are 121 markets. The main feature of this app is to notify the developers with a live tile notification and a toast when an app is in the spotlight.

clip_image001

App Spotlights is a perfect companion for Windows Phone app buyers and an indispensable tool for developers.

Windows Phone Buyers:
★ Access to more than 2400 spotlighted apps from all 121 markets every day.
★ Have more confidence when buying a spotlighted app.
★ Consult three charts to find out the most spotlighted apps in the marketplace.
★ Navigate faster than the built-in Store app when looking for spotlighted apps.

Windows Phone Developers:
★ Get notified when your apps are in the spotlights in any markets. Share the news with potential buyers on your favourite social networks.
★ Obtain a detailed history when your apps were in the spotlight in each market.
★ Analyze the impact on your downloads when your apps are in the spotlight.
★ Track the visibility of your competitors.

Other features:
★ Toast and Live Tile notifications.
★ Lock screen information from App Spotlights can be used.
★ Fast loading and resume.

Note: Spotlight statistics have been calculated since February 17th 2013.

Screenshot 4Screenshot 7

Promotion until April 17th: 33% off

WindowsPhone_208x67_blu

QR

Windows Phone 8 SDK new features for developers

I dug in the Windows Phone 8 object browser and I found some interesting classes:

Microsoft.Phone.Controls.WebBrowserExtensions

In WP7, there is only the GetCookies method.
In WP8, there are the new ClearCookiesAsync and ClearInternetCacheAsync methods.

Windows.Phone.Networking.NetworkOperators.SmsInterceptor

There is a event called SmsReceived which could be really interesting to use. However, there is a little note saying: “This API is not intended to be used directly from your code”.

Windows.UI.Input.EdgeGesture, Windows.Devices.Input.MouseCapabilities and Windows.Devices.Input.KeyboardCapabilities

They all seem interesting, but I was not able to instantiate them. I get this exception: Requested Windows Runtime type ‘Windows.Devices.Input.MouseCapabilities’ is not registered.

Windows.ApplicationModel.Store

This namespace contains a lot of cool classes:

  • LicenseInformation (ExpirationDate, IsActive, IsTrial, ProductLicences).
  • ListingInformation (AgeRating, CurrentMarket, Description, FormattedPrice, Name, ProductListings)
  • ProductLicense (ExpirationDate, IsActive, IsConsumable, ProductId)
  • ProductListing (Description, FormattedPrice, ImageUri, Keywords, Name, ProductId, ProductType, Tag)
  • CurrentApp (GetAppReceiptAsync, LoadListingInformationAsync, LoadListingInformationByKeywordsAsync, RequestProductPurchageAsync)

I hope these classes will be available to use in applications. They could be useful in making marketplace apps!

Windows.System.Launcher

The Launcher class has LaunchFileAsync and LaunchUriAsync. The summary of LaunchUriAsync is: Starts the default app associated with the specified file or protocol.

I tried it with the protocol mailto:email@company.com and it launched the mail application! It will be cool if applications can register file type. Please note that I did not see a way to do that.

There are a lot more, but because I’m not sure if they will be available in the release version, it will better to wait for the final bits of the SDK.

Windows Phone 8 shared core with Windows 8 – File IO

For developers, the biggest news for Windows Phone 8 is that it shares a core with Windows 8. It means that your code has more chances than ever before to be compatible on both platforms.

One of the easier components and surely the most used in applications is the File IO component. In this post, I’ll also cover the Windows Phone 7 code compatibility.

In Windows Phone 7

To write a file, you use the IsolatedStorageFile:

private void WriteFile(string fileName, string content)
{
    using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication())
    {
        using (IsolatedStorageFileStream isolatedStorageFileStream = isolatedStorageFile.CreateFile(fileName))
        {
            using (StreamWriter streamWriter = new StreamWriter(isolatedStorageFileStream))
            {
                streamWriter.Write(content);
            }
        }
    }
}

To read a file:

private string ReadFile(string fileName)
{
    string text;

    using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication())
    {
        using (IsolatedStorageFileStream isolatedStorageFileStream = isolatedStorageFile.OpenFile(fileName, FileMode.Open))
        {
            using (StreamReader streamReader = new StreamReader(isolatedStorageFileStream))
            {
                text = streamReader.ReadToEnd();
            }
        }
    }

    return text;
}

In Windows Phone 8

To write a file, you use the Windows.Storage component. The file and folder objects are respectively IStorageFile and IStorageFolder. The usage of the await and async keywords come in.

To write a file:

public async Task WriteFile(string fileName, string text)
{
    IStorageFolder applicationFolder = ApplicationData.Current.LocalFolder;

    IStorageFile storageFile = await applicationFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

    using (Stream stream = await storageFile.OpenStreamForWriteAsync())
    {
        byte[] content = Encoding.UTF8.GetBytes(text);
        await stream.WriteAsync(content, 0, content.Length);
    }
}

To read a file:

public async Task<string> ReadFile(string fileName)
{
    string text;
    IStorageFolder applicationFolder = ApplicationData.Current.LocalFolder;

    IStorageFile storageFile = await applicationFolder.GetFileAsync(fileName);

    IRandomAccessStream accessStream = await storageFile.OpenReadAsync();

    using (Stream stream = accessStream.AsStreamForRead((int)accessStream.Size))
    {
        byte[] content = new byte[stream.Length];
        await stream.ReadAsync(content, 0, (int) stream.Length);

        text = Encoding.UTF8.GetString(content, 0, content.Length);
    }

    return text;
}

You can use these methods this way:

await WriteFile("Dummy.txt", "I love the Windows Phone");
string text = await ReadFile("Dummy.txt");

You can see that the code between Windows Phone 7 and Windows Phone 8 is quite different.

Compatibility

As we know already, Microsoft announced that the Windows Phone 7 applications will run on Windows Phone 8. This is great news. What is even better is that your Windows Phone 7 code that uses the IsolatedStorage will compile without any changes in Windows Phone 8. You can take the Windows Phone 7 code above and it will work.

You might be wondering if the internal folder structure is different between WP7 and WP8… The difference is minor.

In WP7, if you create a file at the root, the file will point to:

C:DataUsersDefaultAppAccountAppData{9679D8C4-24B4-41DF-85C5-5E099947F109}LocalIsolatedStoreDummy.txt

In WP8, the same file created at the root will be in:

C:DataUsersDefaultAppAccountAppData{9679D8C4-24B4-41DF-85C5-5E099947F109}LocalDummy.txt

The difference is the IsolatedStore folder added in WP7. It means that if you have old WP7 code that you would like to use with new WP8 code, you just have to get the IsolatedStore folder:

IStorageFolder applicationFolder = 
    await ApplicationData.Current.LocalFolder.GetFolderAsync("IsolatedStore");

In the end, you can mix both WP7 and WP8 code in your next Windows Phone 8 application. However, I would encourage you to use only the Windows Phone 8 version, as it will then be easier for you to use the same code in Windows 8.

Windows Phone 8 Battery API

The Battery API makes a nice addition to the WP8 SDK.

I can see in the near future that some applications will display the battery metrics on a Live Tile or in the application that hides the System Tray.

The Battery API is pretty easy to use:
1- Get the Battery instance with Battery.GetDefault().
2- Bind to the event RemainingChargePercentChanged.

The battery properties are:
RemainingChargePercent: gets a value that indicates the percentage of the charge remaining on the phone’s battery.
RemainingDischargeTime: gets a value that estimates how much time is left until the phone’s battery is fully discharged. 

With the following code:

using Windows.Phone.Devices.Power;

namespace BatteryApp
{
    public partial class MainPage
    {
        private readonly Battery _battery;

        public MainPage()
        {
            InitializeComponent();

            _battery = Battery.GetDefault();

            _battery.RemainingChargePercentChanged += OnRemainingChargePercentChanged;

            UpdateUI();
        }

        private void OnRemainingChargePercentChanged(object sender, object e)
        {
            UpdateUI();
        }

        private void UpdateUI()
        {
            textBlockRemainingCharge.Text = string.Format("{0} %", _battery.RemainingChargePercent);
            textBlockDischargeTime.Text = string.Format("{0} minutes", _battery.RemainingDischargeTime.TotalMinutes);
        }
    }
}

You get:

image


Please note that when running this on the emulator, it will show 100% and an infinite discharge time. The above values are fake.

Get ready to code!

Windows Phone 8 upcoming Live Tile feature

With all the buzz this week about the Windows Phone 8 SDK leak, I couldn’t resist installing it.

The title of the SDK is Windows Phone 8 Developer Preview. There are so many cool new features that initially, I didn’t know where to start. I decided to start with one of the new features of the live tiles, since this is the Windows Phone’s biggest strength.

I don’t know the exact feature name, but it’s about cycling images in a live tile. Here is a little video that will help to describe the feature.

Cycling images in a Live Tile

Have you spotted the difference between the Windows Phone 7 badge count and the new OS? It is now in a square instead of a circle!

What I love about Microsoft is that they make it easy for developers to use their APIs.

Follow these two steps to accomplish what you see in the video:
1- Add up to 9 images to the project and set the Build Action to Content. The images need to be local only.
2- Append the following code

ShellTile appTile = ShellTile.ActiveTiles.First();

if (appTile != null)
{
    Uri uri1 = new Uri("/Assets/UltimatePokerManager.png", UriKind.Relative);
    Uri uri2 = new Uri("/Assets/YourShape.png", UriKind.Relative);

    CycleTileData cycleTileData = new CycleTileData
                                        {
                                            Count = 3, 
                                            CycleImages = new[] {uri1, uri2}
                                        };

    appTile.Update(cycleTileData);
}

The UtimatePokerManger.png and YourShape.png have the size 173×173. When you watched the video, the images were expanded.

Please note that the SDK is in preview and there is no guarantee that the APIs will be the same in the released version, but I bet this feature will stay as it is.

This was my first Windows Phone 8 blog post and is surely not the last!