How to create Secondary tiles on Windows phone start screen using c#

This is the third blog post of this series in which I am going to explain you how to create a secondary tile on Windows phone start screen.

 

Before going ahead I would like to give you a short summary on Secondary tiles.

 

What are Secondary tiles?

A secondary Tile is created programmatically by an application based on interaction from the user. Typical uses for a secondary Tile include scenarios where you want to show important information to the user on the Start screen of the phone.

 

1. First of all create a new project having the name Secondarytiles.

 


 

2. Then create a new image folder having the name Images in your project and add some sample images to it.

 


 

3. We shall be using Create(Uri, ShellTileData) method to create a Tiles on Start Screen. Whenever this method will be called the UI will navigate to Start Screen.

 

The different parameters in the above method are

1. Uri – It is the Uri of any page within the application where the application will navigate to whenever user taps on this tile from start screen. It should be unique for each secondary tile. By unique uri we mean that more than one tile can navigate to the same page but each should have different tag in the uri which will be explained in the further post.

2. ShellTileData– This data class is used to provide different properties to the tiles created through this method. It can be of different types.

 

Note: One property of the Secondary tiles which are created through the above method is that each should have a unique uri.

 

So if we try to create more than one secondary tile having the same uri. It will give an exception and will lead to crash. So as to avoid the following situation we use the following method checktile given below to check whether any tile with same uri exist before or not on start screen.

 

 

As there are three different tile templates in Windows phone 8/8.1. We will be discussing an example of each of the types.

 
http://www.windowsapptutorials.com/windows-phone/different-tile-templates-properties-windows-phone
 


 

Flip tile

For creating a flip tile on start screen we shall be using FlipTileData class as discussed in our previous post.

Create a button on the MainPage to pin the tile. The code for click event handler of the button is given below.

 

 

Output Images:

 

Front


Back


 

Cyclic tile

For creating a cyclic tile on start screen we shall be using CyclicTileData class as discussed in our previous post.

Create a button on the MainPage to pin the tile. The code for click event handler of the button is given below.

 

 

Output Images:

 

Medium


Wide


 

Iconic tile

For creating an iconic tile on start screen we shall be using IconicTileData class as discussed in our previous post.

Create a button on the MainPage to pin the tile. The code for click event handler of the button is given below.

 

 

Output Images:

 

Medium


Wide


 

As a developer I would like you to experiment with the different tile templates to get a better understanding of tiles.

 

I hope this post will be helpful to you. If you have any doubts related to this post you can download the full project from link from the link given below.

 
Download full project source Secondarytiles.zip
 

In the next blog post of this series I will explain you how to update and delete secondary tiles pinned on start screen.

 
Introduction to tiles in Windows phone app
Different tile templates and their properties in Windows phone
How to update and delete Secondary tiles on Windows phone start screen using c#

Using Ad Mediation in Windows Phone 8 app

Ad mediation is an algorithm that enables your app to use multiple SDKs. This means that with the mediation code in place, your app will make a call to one ad control, and if that ad control cannot serve an ad, the app will then call a second ad control, then a third, and so on. The new ad mediation control provides a simple way to implement this capability in your apps. It offers several advantages over using a single ad network, giving you control to integrate multiple ad SDKs and optimize use based on performance. The highest revenue return can be achieved by choosing the ad network with highest eCPM first, then serving the unfilled ads from other ad networks. Here are some attractive features offered by Ad Mediation for Windows Phone

  • App level configuration
  • Global and optional market-specific configuration
  • Ad refresh rate
  • Pause/Resume ads
  • Ad network prioritization (e.g. specific network first, equal distribution, back-up only)
  • Ad network exclusion (do not use this ad network, globally or in a specific market)
  • Fill rate reporting by ad network and by market

Windows ad mediation capabilities are initially launching for Windows Phone 8.0, 8.1 Silverlight and 8.1 XAML. Currently you can use Microsoft Advertising, AdDuplex, Inneractive, Smaato, AdMob, InMobi and MobFox with Ad Mediation. You will need to set up an account on each of the ad providers that you plan to use and create an ad unit in it. Here are the steps to use Ad Mediation in your Windows Phone 8 app.

Step 1. Download and install the Windows Ad Mediator Extension

Before you can use Ad Mediator in your apps, you need to download and install Ad Mediator Extension. The Ad Mediation control will appear in the toolbox next time you open Visual Studio.

 

Step 2. Add the Ad Mediation control

From the Toolbox, drag a new AdMediatorControl into the designer. Position the control in the location where you’d like your ads to display. You can add multiple controls if you want to display ads in more than one area of your app. Be sure to drag the control into the designer, not into your XAML code. Code will be generated for the control, including a unique ID and a name for the control. Here is how it can be done in a Windows Phone 8 Silverlight application:

  The Name element will help you to identify the specific control in your app when you configure your ad mediation. You can change this to whatever you’d like, but be sure not to change or duplicate the Id element. This Id must be unique for each control within your app.

Step 3. Configure the controls

Once you’ve added all the controls you’d like, you’re ready to configure them through Connected Services. Note that if you add an additional AdMediatorControl later, you’ll need to configure it through Connected Services again. Otherwise, the new control will not be able to use ad mediation. To configure the controls, right-click the name of the project in Solution Explorer, click Add, and then click Connected Service… to launch the Services Manager window. By default, the Microsoft Advertising DLLs will be added, and Microsoft Advertising will be enabled. If you don’t want to use this ad network, you can remove it in the next step. For each of the selected ad networks, click on configure hyperlink to set the ad unit id for that ad provider. Even if you don’t configure the Ad Controls in the app, it can be done in the Windows Phone Developer Portal without needing to update the app again.

Step 4. Add or remove Ad Networks

To add and remove ad networks, click Select ad networks. You’ll see a list of all the ad networks that are supported for your project. Check the boxes of the ad networks you want to use. After you’ve selected your ad networks, click OK. The control will attempt to retrieve the DLLs for each ad network. You’ll see the progress and result of this process. Click OK, and you’ll be able to see which DLLs were successfully fetched.

Note: In some cases, you may see that certain DLLs were not fetched (for example AdMob as it is not available on Nuget). In this case, you’ll need to add them manually. For links to download individual assemblies, see Selecting and managing your ad networks.

 

Note

If you decide to add another ad network after doing this configuration, you’ll need to open the Services Manager window again, select the network, and ensure the DLLs are added.

Step 5. Add the required capabilities

Each ad network may require certain app capabilities. These are shown by each provider in the Services Manager window. Be sure to declare all of the required capabilities in your app’s manifest so that the ads are properly displayed.

Step 6. Handle unhandled exceptions from Ad Networks

As part of our testing, we’ve identified a number of unhandled exceptions from specific ad networks that must be handled within the app to avoid app crashes related to these exceptions. We highly recommend that you copy and paste the code sample below to your App.xaml.cs file. Code for Windows Phone 8 Silverlight application

Code for Windows Phone 8.1 XAML application

Step 7. Test the application

Running your app in the Windows Phone Emulator is a good first step. When you do so, test metadata will be used, so you can test your app and make sure it’s coded correctly before you’ve even entered your ad network required parameters. When you run your app in the emulator, the ad networks will rotate in sequential order, with one network displayed after another for equal amounts of time. Be sure to wait long enough to run through a few cycles so you can view all ad networks and reduce the chance of any temporary connectivity issues which may occur. Test ads will be displayed (for ad networks which support them).

 

Step 8. Submit the app and configure ad mediation

Once you’ve built your app to include all of the ad networks you may want to use, and tested it to ensure everything’s working, you’re ready to submit the app. During the submission process, you can configure the ad mediation behavior you’d like to see. You’ll be able to adjust this later without having to make code changes or submit new packages.
When you upload your packages, Dev Center automatically detects that you’re using ad mediation and identifies which ad networks you’re using. On the package upload page, you’ll see an Ad mediation configuration section. This is where you’ll configure your mediation logic. The first time you submit your app, you’ll create a baseline configuration. After that’s set up, you can add market-specific configurations to take advantage of specific ad networks’ strengths in different markets.

If you want to adjust your ad mediation for a specific app, you can do so at any time without having to resubmit the app. This is useful if you’ve already added ad networks into your app that you hadn’t previously set up accounts for, or if you’re finding that one ad network is not able to fill ads reliably in specific markets.

To make changes, view the app details page in Dev Center and click Ad mediation. You can make changes to your baseline configuration as well as to market-specific configurations. You can also add or remove market-specific configurations if desired.

You can download the project source code and use it as an reference.
Download full project Ad-Mediation-Demo.zip

Isolated Storage in Windows phone app – Reading and saving images

This is the fourth post regarding Isolated Storage in Windows Phone app. In this post I am going to talk about How to read and save captured images in isolated storage.

Note: To understand this post better you should test the following code on a real phone not an emulator as camera of emulator will give you a black screen.

 

1. Before starting with this post you should have a better understanding of Photochoosertask and CameraCaptureTask.

 

If you don’t have any idea about these tasks you can refer to the following post.

http://www.windowsapptutorials.com/launchers-and-choosers/launchers-and-choosers-how-to-choose-photo-from-media-library-or-capture-a-new-one-in-windows-phone-app/

 

2. In the following post first I will explain you how to save and read the image chosen from medial library into isolated storage. Then I will explain you how to save the image captured from camera into the isolated storage and how you can read that image from isolated storage.

 

Both the tasks have similar code for saving and reading the image except the code for launching the tasks.

 

3. First create a blank project Saveimages.

 


 

4. Add the following namespaces to the page MainPage.xaml.cs.

 

 
5. Now first we will launch the photochoosertask and will select a image from media library and will save it to isolated storage.

 

Save the existing image

First create a button to save the existing image and add the following code to click event handler of the button.

 

 
The Task completed event handler of the choosertask will save the image to the isolated storage having the file name existing.jpg. The code is given below.

 

 

Now you can read the image from isolated storage and display it in the imagecontrol given on the MainPage by clicking on the read selected image button. The following code is given below.

 

 

Save the captured image

The procedure for the CameraCapturetask is same as that of photochooser. We will create a button to launch the CameraCapturetask and will save the captured image in isolated storage having the name captured.jpg.

 

 

 

 

We can read the captured image in the same way as we did for the Photochooser task. The code for the read captured image button is as shown below.

 

 

Note: You will observe that the code for both the tasks will be similar as there is no difference between the read save image code of both the tasks except the filename.

 

 

 

6. I hope this post will be helpful to you. You can download the full project source file from the link given below.

 
Download Full Project file Saveimages.zip
 
 
Isolated Storage in Windows Phone app – Introduction
Isolated Storage in Windows phone app – Store data in IsolatedStorageSettings
Isolated Storage in Windows phone app – Reading and saving text files