wp7appdevelopment

Adventures in Windows Phone app development

Monthly Archives: November 2013

Capabilites Needed for PubCenter Advertising

You need to include the following capabilities in the manifest (WMAppManifest.xml) of apps that use PubCenter ads.

Silverlight Apps: Windows Phone 8

  • ID_CAP_IDENTITY_USER
  • ID_CAP_MEDIALIB_PHOTO
  • ID_CAP_NETWORKING
  • ID_CAP_PHONEDIALER
  • ID_CAP_WEBBROWSERCOMPONENT

Silverlight Apps: Windows Phone 7

  • ID_CAP_IDENTITY_USER
  • ID_CAP_MEDIALIB
  • ID_CAP_NETWORKING
  • ID_CAP_PHONEDIALER
  • ID_CAP_WEBBROWSERCOMPONENT

more info: http://msdn.microsoft.com/en-us/library/advertising-mobile-windows-phone-manifest-capabilities(v=msads.20).aspx

Localize Windows Phone 8 App

Localizing App

First, follow the directions on “How to build a localized app for Windows Phone” post.  You’ll need to:

  • Replace hard-coded strings (textblocks, button content, headers, etc.) with strings from a resource file.  For example:
    <TextBlock Text="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}" 
        Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
  • Then, in Visual Studio, go to the project’s Properties page, and in the Supported Culture box, select the other languages you want to support.
    After you save the project, Visual Studio will automatically create new resources files (one for each language).  These files will have copies of the original language. You’ll need to edit them with the translated values.

Localizing the App bar

You have a choice: you can define your app bar in the XAML or in the C# page code-behind. But, the XAML app bar doesn’t support dynamic data binding. So, you’ll need to add a method to create the app bar and call it in your constructor or other method.

// Build a localized ApplicationBar
private void BuildLocalizedApplicationBar()
{
    // Set the page's ApplicationBar to a new instance of ApplicationBar.
    ApplicationBar = new ApplicationBar();

    // Create a new button and set the text value to the localized string from AppResources.
    ApplicationBarIconButton appBarButton = 
        new ApplicationBarIconButton(new   
        Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
        appBarButton.Text = AppResources.AppBarButtonText;
    ApplicationBar.Buttons.Add(appBarButton);

    // Create a new menu item with the localized string from AppResources.
    ApplicationBarMenuItem appBarMenuItem = 
        new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
    ApplicationBar.MenuItems.Add(appBarMenuItem);
}

 

Localizing App Title

Follow the directions on:

  • “How to localize an app tile for Windows Phone” post.
    [Note: this procedure moves the final *.mui files to the Resources folder. In my testing, this didn’t work. Leaving them in the root directory worked correctly.]
  •   “Language-Neutral Resource Project” post.

I don’t have Visual Studio (only Visual Studio Express), so I needed to download their “Language-Neutral REsource Project. However, in order to compile it, I needed to do the following:

  1. Replace the ‘include “afxres.h” ‘ by ‘ include “winnt.rh” ‘
  2. Delete all included libraries in Project tab, Properties > Linker > Input > Additional Dependencies

Best Example

The best example I found for Windows Phone 8, using Visual Studio Express for Windows Phone 2012 included these instructions.

Applies to: Windows Phone 8 only

This project is a language-neutral resource DLL project. You can use it to create localized language resource strings for your Windows Phone app title and app Tile title.

Important Note:
You can use this language-neutral resource project in Visual Studio Express 2012 for Windows Phone or Visual Studio to create localized app title and app Tile title string for your Windows Phone app. For more information, see How to localize an app title for Windows Phone.

Creating language resource strings for your app

In this set of procedures, you use Visual Studio or Visual Studio Express 2012 for Windows Phone to edit the language-neutral resource string table to contain localized resource title strings. Then, you rebuild the DLL that contains the new localized title strings and rename the DLL file.

Creating the first specific language resource strings

In this procedure, you create localized title strings for English (United States).

To create the first specific language resource strings for your app

  1. Open the DLL project that you downloaded in Visual Studio or Visual Studio Express 2012 for Windows Phone.
  2. In Solution Explorer, expand the Resource Files folder.
  3. Right-click the AppResLib.rc resource, and then click View Code.
  4. Modify the AppResLib.rc file by changing the resource string values as follows:
    ID Value
    AppTitle en-US App Title
    AppTileTitle en-US Tile Title

    The AppTitle string contains the English (United States) name of your app to be displayed in the app list. The AppTileTitle string contains the English (United States) name of your app to be displayed in the app Tile when pinned to Start.

  5. In the Build menu, select Build Solution.
  6. In Solution Explorer, right-click Solution ‘AppResLib’, and then click Open Folder in File Explorer.File Explorer displays the project files.
  7. In File Explorer, open the Release folder, and locate the latest AppResLib.dll file that you built.
    Note:
    The project folder and the solution folder both contain a Release folder. The AppResLib.dll file is contained in the Release folder at the root of the solution. The solution folder is easy to recognize because it contains the AppResLib.sln solution file.
  8. Rename the file AppResLib.dll file to AppResLib.dll.0409.mui.

The DLL file that you created and renamed contains the English (en-US) app title and the app Tile title. Later, you use this file in your Windows Phone app. Your Windows Phone app recognizes this file based on the 0409 LCID value that represents English (en-US).

Creating additional language resource strings

You can create more language resource strings and the DLL that contains those resources by following the preceding procedure. For each localized set of resource strings, you create a new DLL and rename it with the LCID and .mui extension.

Repeat the previous procedure, however, you must provide a localized AppTitle string value and AppTileTitle string value for each locale. You must also rename the DLL file for each locale. Each DLL file name has the format AppResLib.dll.[locale ID].mui. For more information about supported display languages, culture codes, and culture values, see How to localize an app title for Windows Phone.

In the next procedure, you copy the MUI files and language-neutral DLL file to the root directory of your Windows Phone app.

Using the localized resource strings in your Windows Phone app

By adding the localized MUI files and the language-neutral DLL file to your Windows Phone app, app users see the localized app title and the localized app Tile title based on the selected Windows Phone language that they choose for their Windows Phone.

To use the localized resource strings in your Windows Phone app

  1. Open your existing Windows Phone 8 app or create a Windows Phone 8 app in either Visual Studio or Visual Studio Express 2012 for Windows Phone.
  2. In Solution Explorer, select your Windows Phone 8 project.
  3. On the Project menu, click Add, and then click Existing Item.The Add Existing Item dialog box appears.
  4. Find and select the AppResLibLangNeutral.dll file and all the AppResLib.dll.*.mui files that you created in the preceding procedures, and then click Add.The files are added to the root your Windows Phone project.
  5. In Solution Explorer, right-click the AppResLibLangNeutral.dll file and rename it to the following:AppResLib.dll
  6. In Solution Explorer, select the imported files (AppResLib.dll and AppResLib.dll.*.mui).In the Properties window, set the Build Action property to Content.
    Note:
    If the Properties window is not displayed, select Properties Window from the View menu.
  7. In Solution Explorer, expand Properties and then open the WMAppManifest.xml file.The Windows Phone app manifest designer is displayed.
  8. Select the Application UI tab if it’s not already selected.
  9. Set the Display Name to the following:@AppResLib.dll,-100
  10. Set the Tile Title to the following:@AppResLib.dll,-200
  11. Save and build the Windows Phone app.

The Windows Phone 8 app displays the localized app title and the app Tile title based on the language and country settings of the user’s Windows Phone 8 phone. The AppTitle string and AppTileTitle string contained in the .mui files correspond to the language and country setting of the user’s Windows Phone 8 phone. If you don’t include a matching .mui file for a specific supported locale, your Windows Phone 8 app uses the language-neutral AppTitle string and AppTileTitle string contained in the AppResLib.dll file.

Testing the localized title

To test your localized app title, follow the steps listed at How to test a localized app for Windows Phone.

Windows Phone 8: Fast App Resume

Fast App Resume is a feature that controls how an app resumes from Start. When a user launches the app from the Start menu or the App list, what do you want to happen? Do you want a completely new instance of the app to be created? Or do you want to user to be able continue with whatever page they were on when they last used your app?

To enable Fast App Resume, all you need to do is manually edit the WMAppManifest.xml file:

<DefaultTask Name="_default" NavigationPage="MainPage.xaml" ActivationPolicy="Resume|Replace" />

But of course it’s not quite that simple. You also need to think about how users interact with your app and what you want to happen if they re-launch your app from the Start page or App list.   Do you want them to Resume, or get a Fresh Start experience, or do you want it to depend on how long ago they last used your app.

Here’s a great blog post that explains it:

http://blogs.windows.com/windows_phone/b/wpdev/archive/2013/09/19/windows-phone-fast-app-resume.aspx

A more complete example is available from Microsoft:

http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj735579(v=vs.105).aspx

And finally, and sample project you can download:

http://code.msdn.microsoft.com/wpapps/Fast-app-resume-backstack-f16baaa6