lundi 25 janvier 2016

Deploying your Universal Application (UWP) on only one platform/device type using TargetDeviceFamily

What I want to do is deploy my Universal Application (UWP) on a single platform (Desktop in my case) at first, then afterward deploy it on another device family. You can find all the device familes Here.

When you create a UWP application find the file called Package.appxmanifest open it with notepad, and by default under Dependencies you should see this:

    <TargetDeviceFamily Name="Windows.Universal" MinVersion="" MaxVersionTested="" />

Which is probably topically what you would want to, which is to have TargetDeviceFamily Name="Windows.Universal" which means that it targets all of the Windows 10 devices!

However in my case I just want to target the desktop app, thus I need to set  TargetDeviceFamily Name to Windows.Desktop as follow:

    <!--<TargetDeviceFamily Name="Windows.Universal" MinVersion="" MaxVersionTested="" />-->
    <TargetDeviceFamily Name="Windows.Desktop" MinVersion="" MaxVersionTested="" />

And there you have it.

Targeting different platform type:

Here are the different Names that you can set TargetDeviceFamily, so that it only works on:
  • Mobile
    <TargetDeviceFamily Name="Windows.Mobile" MinVersion="" MaxVersionTested="" />

  • Desktop
    <TargetDeviceFamily Name="Windows.Desktop" MinVersion="" MaxVersionTested="" />

  • Xbox
    <TargetDeviceFamily Name="Windows.Xbox" MinVersion="" MaxVersionTested="" />

  • Iot
    <TargetDeviceFamily Name="Windows.Iot" MinVersion="" MaxVersionTested="" />

Good luck,

Msdn reference:

dimanche 24 janvier 2016

Drag and Drop elements instead of using a FilePicker on Windows 10

Picking files with a FilePicker is no fun, why not let our users be able to drag and drop files in your application?

In this example I will show you who to implement a very simple drag and drop feature so that your users can just select a file they what to add to your app and just drag and drop it into your application.

First lest start by creating a Stackpanel and then we can start looking in the properties called Drop DragOver and AllowDrop:

Information taken from my IDE (Visual Studio):
We can see that Drop has the following information:

public event Windows.UI.Xaml.DragEventHandler Drop
    Member of Windows.UI.Xaml.UIElement

Occurs when the input system reports an underlying drop event with this element as the drop target.

We can see that DragOver has the following information:

public event Windows.UI.Xaml.DragEventHandler DragOver
    Member of Windows.UI.Xaml.UIElement

Occurs when the input system reports an underlying drag event with this element as the potential drop target.
And that AllowDrop has the following information:

public bool AllowDrop { get; set; }
    Member of Windows.UI.Xaml.UIElement

Gets or sets a value that determines whether this UIElement can be a drop target for purposes of drag-and-drop operations.

true if this UIElement can be a drop target for purposes of drag-and-drop operations; otherwise, false. The default is false.

Lets get coding

In you XAML page you are going to want to create a StackPanel with the properties we saw above and add a small piece of text so that your users can see where to drop the file.

  Text="Drag and Drop your File here" />

In your .cs file you just need to handle the events  StackPanel_Drop and StackPanel_DragOver. In the event StackPanel_Drop you will just need to handle the file that the user is dropping in it, thanks to e.DataView.GetStorageItemsAsync() you are able to fecth the file the user wants to share with you and then you convert the first element in the array into a StorageFile and you are good to go.

Here is the code:

private async void StackPanel_Drop(object sender, DragEventArgs e)
            if (e.DataView.Contains(StandardDataFormats.StorageItems))
                var items = await e.DataView.GetStorageItemsAsync();
                if (items.Any())
                    var storeFile = items[0] as StorageFile;
                    //Do what ever you wish with the StoreFile
                    //You code goes here

private void StackPanel_DragOver(object sender, DragEventArgs e)
            e.AcceptedOperation = DataPackageOperation.Copy;

From here you can now upload the file to your server, or do whatever you wish!

Bonus: Just to make sure that users dont send you the wrong kind of file, its always a good idea to check the file extension. Here is a tiny method that will allow you check for different extensions on you file:

 private bool CheckFileExtension(string fileExtension)
            string[] AllowedExtensions = new[] {".abc", ".def", 
            ".ovf" };

            return !AllowedExtensions.Contains(fileExtension);

Happy Coding!

mardi 5 janvier 2016

Using Windows Ad Mediation to improve your revenue in the Windows Store on a Window 8/10 application

Windows Ad Mediation is a great tool that can help you improve your revenue in your applications, in this example I will show you how to setup your application so that you can use Windows Ad Mediation in it. In this example we will be using an application called SampleApp test.

To start log into your windows center account and look into the application you wish to monetize.  Next you will want to click on Monetization and then click on Monetize with ads, you will arrive here:

Creating Advertising Unites

When you are on the Monetize with ads  page you will need to scroll down a bit and create one or two (or more) advertising ad unites, be careful when you create them (the ad unites) as some will be specific for PC/Tablet and other are specific only for Mobile apps.

Adding Ad Mediator to your application 

Open you application, click on references and select "Add a Connected Service" as follow:

Then select Ad Mediator:

Select which ad networks you wish to work with:

Configuring PubCenter

Next click on Configure button located on the previous screenshot. You should see this:

You can now set you different Application ID and Ad unit ID for Mobile and PC/Tablet apps.

Ad Mediator Element

Now you need to add the ad mediator element to your XAML page, look in your toolbox you should have a control called AdMediator Universal and take the AdMediatorControl and drop it in your application.

This is the AdMediatorControl element that was created for me:


Here are the different ad size that you can use for the Ad Mediator:

For Windows 10 and Windows 8.1 we have:160 x 600

  • 250 x 250 
  • 300 x 250
  • 300 x 600
  • 728 x 90

Windows 10 Mobile, Windows Phone 8.1 and Windows Phone

  • 300 x 50
  • 320 x 50
  • 480 x 80
  • 640 x 100

Also a nice thing to know is that you can programmatically set  the height and width for specific ad network for example you could want a specific add size from Adduplex, another from Pubcenter and use Microsoft in house Advertising as a backup.

For Microsoft Advertising:

AdMediator_BE6310.AdSdkOptionalParameters[AdSdkNames.MicrosoftAdvertising]["Width"] = 300;
AdMediator_BE6310.AdSdkOptionalParameters[AdSdkNames.MicrosoftAdvertising]["Height"] = 250;

Or others (AdDuplex/MicrosoftAdvertisingHouse):

AdMediator_BE6310.AdSdkOptionalParameters[AdSdkNames.AdDuplex]["Width"] = 250;
AdMediator_BE6310.AdSdkOptionalParameters[AdSdkNames.AdDuplex]["Height"] = 250;

AdMediator_BE6310.AdSdkOptionalParameters[AdSdkNames.MicrosoftAdvertisingHouse]["Width"] = 300;
AdMediator_BE6310.AdSdkOptionalParameters[AdSdkNames.MicrosoftAdvertisingHouse]["Height"] = 600 

Setting the weight distribution of your ads

Once you have uploaded the application to the Windows Store, under Windows Ad mediation you should see something like this depending on what ad platforms you have selected:

you could set the ad network as follow:

If you had ad duplex you could decide to use ad duplex as a backup or give it a percentage of how much you wish for it to be used.

You can go even further and select your baseline witch means that you could give specific weight to different ad providers depending on which country the ad is being displayed.

For example: lets say that hypocritically Smaato had a higher eCPM in France then PubCenter did, then I would highly recommend that you set your baseline with PubCenter with the highest Weight and then create a specific baseline for France with Smaato with the highest Weight and PubCenter with a lower Weight.  This would mean that for the whole world PubCenter would have the highest Weight and for France we would have a specific configuration which would have Smaato that would have the highest Weight compared to PubCenter.

/!\ I have NO IDEA which provider PubCenter or Smaato has the highest eCPM in france, it is just an example!

And there you have it,  good luck and happy coding.