Archives For windows 8

tips word in wood type

In a recent post I showed you how to register your background audio capable Windows Store apps for media transport control. This is a requirement in order to get your app into the Windows Store. To provide a great user experience you’ll also want to consider registering for sound level notifications. I’ll show you how to do so in this post.

Sound level notifications are new in Windows 8 and provide your Windows Store apps with information on its audible state (muted, low, and full). Your apps can query the system at any time to determine what state it is in, and apps can subscribe to system events when their audible state changes. While it is up to you, the developer, the determine the best behavior for your app upon receiving a sound level notification, there are some guidelines you can follow based on audible state:

Audible State Suggest Behavior
Full No change required
Muted Pause playback
Low In this case it is likely that a Real-Time Communications app (i.e. Skype or Lync) is in use at the same time. Your app can either continue playback or pause playback, whichever you deem most appropriate. Better yet, why not make it a setting within your app and let the user decide!

In the case of my Radio Soma app, I pause playback when a Muted or Low sound level notification is received. Here’s some abbreviated code to show how I’m handling it:

Hope it helps!

Additional Resources:

Over the past several weeks I’ve been working on some content I’m excited to finally share with you through a series of blog posts. This series will introduce you to Windows 8 development from an Android developer’s perspective. Through the course of the series you’ll create your first app. It won’t be anything pretty, but you’ll learn the ins and outs of the development environment, how to create a simple user interface, and how to perform navigation. Along the way you’ll see some Android Hints that will help make it easier for you to transition your existing skills to the Windows platform. You’ll also see some Visual Studio Tips to make you more productive in your development environment. Good luck!

In the last lesson you created your first Windows Store project. In this lesson you’ll spend some time exploring the project and learning about some key files and directories.

Package.appxmanifest


This is the application’s manifest. It is an XML document that contains the information the system needs to deploy, display, or update a Window Store app.

ANDROID HINT

Package.appxmanifest is similar to the AndroidManifest.xml file used by Android applications.

 

Here is some additional information about the manifest:

  • It includes package identity, package dependencies, required capabilities, visual elements, and extensibility points.
  • Every app package must include one package manifest.
  • The manifest is digitally signed as part of the signing the app package.
  • After signing, you can’t modify the manifest without invalidating the package signature.
  • After the package has been installed, the package manifest file appears in the directory for the installed package.

If you double-click the manifest in the solution explorer you’ll get a UI you can use to edit the various properties of the manifest. For this app we’ll leave everything as is.

MainPage.xaml and MainPage.xaml.cs


As mentioned in the last lesson XAML (eXtensible Application Markup Language) is the declarative language used to create the UI for Windows Store applications. MainPage.xaml is the default page for your application. This is where you’ll create your simple UI (in the next lesson). MainPage.xaml.cs is the associated C# code that goes along with your UI.

VISUAL STUDIO TIP

The *.xaml.cs file that is associated with a *.xaml file is called the code-behind file.

 

ANDROID HINT

The relationship between *.xaml and *.xaml.cs files is similar to the relationship between layouts and activities in Android development. When you create a generic Android app, you’ll get an activity_main.xml file in the res > layout
directory. This is where you define the UI for your Android app. You also get a MainActivity.java file in your src directory. This is where you write the code that goes along with the UI. In our app MainPage.xaml corresponds to activity_main.xml, and MainPage.xaml.cs corresponds to MainActivity.java

 

App.xaml and App.xaml.cs


App.xaml can be used to store information about application wide resources. By default a ResourceDictonary is added that refers to the StandardStyles.xaml file in the Common directory. (More on that in a minute).

App.xaml.cs provides application-specific behavior to supplement the default application class. This is where the connection to MainPage.xaml as the default page for the application is wired up

ANDROID HINT

In the generic Android app example I mentioned earlier, you set the default activity for the app in AndroidManifest.xml. Typically it looks something like this:

If you open up App.xaml.cs and navigate to the bottom of the OnLaunched method you’ll see the following:

This is what tells the app to display MainPage.xaml when it starts.

 

Assets Directory

The Assets directory contains default artwork used for the application’s tiles, splash screen, etc.

ANDROID HINT

The items contained in the Assets directory are similar to those found in the res/drawable-* directories of your Android projects.

 

Common Directory

The Common directory contains resources used across the application. By default it contains one file, StandardStyles.xaml. This file gives you the styles you need for your app to look like a Windows 8 (i.e. Metro application). You are not required to use it, but it’s a great resource for those of us who are design challenged.

As you can see, Visual Studio gives you a lot for free so you can get started on your app. You should continue to explore your project set up as well as the files and directories that get created with the of the other project templates as Visual Studio does a lot of heavy lifting for you.

In the next lesson you’ll learn how to run your application.

Previous Posts in this Series

  1. Setting up the Development Environment
  2. Creating Your First Windows Store Project

Additional Resources

tips word in wood type

In a recent post I showed you how to enable your apps to play audio in the background (i.e. when the app is not running). I also warned you that your app would not pass certification.The reason for this is that any app that plays background audio is required to register for media transport control. This system wide control allows a user to control a music application that is in the background as well as get the current information on which track is playing. What this really means is that your app needs to hook into this control:

image

This is activated when the user presses the hardware Volume Up or Volume Down keys on the device or any of the transport controls (i.e. Play, Pause, and Stop).

At a minimum your app will need to handle the PlayPressed and PausedPressed events of the MediaControl class. For good measure I also recommend handling the PlayPauseTogglePressed event. The following are some quick examples of how I handled these events in my Radio Soma app.

For handling the PlayPressed event I set a local field to true, call the Play method of a MediaElement and set the IsPlaying property of the MediaControl to true:

For handling the PausePressed event, I set a local field to false, call the Pause method of a MediaElement and set the IsPlaying property of the MediaControl to false:

For handling the PlayPauseTogglePressed event I perform the appropriate action based on the current state of the MediaElement:

Next up, understanding and handling changes in sound level.

Additional Resources:

Over the past several weeks I’ve been working on some content I’m excited to finally share with you through a series of blog posts. This series will introduce you to Windows 8 development from an Android developer’s perspective. Through the course of the series you’ll create your first app. It won’t be anything pretty, but you’ll learn the ins and outs of the development environment, how to create a simple user interface, and how to perform navigation. Along the way you’ll see some Android Hints that will help make it easier for you to transition your existing skills to the Windows platform. You’ll also see some Visual Studio Tips to make you more productive in your development environment. Good luck!

In the last lesson you set up your development environment which included installing Visual Studio. In Visual Studio, you create apps for Windows 8 by creating a Windows Store project. The Windows Store project contains all the files that comprise the source code for your app. Visual Studio makes it incredibly easy to start a new project with a set of default files and directories.

ANDROID HINT

The Windows Store project template in Visual Studio is similar to the Android Application Project template that is added to Eclipse when you install the ADT Plugin.

 

In this lesson you’ll learn how to create your first Windows Store project.

  1. Open Visual Studio 2012.
  2. Click New
    in the toolbar.
  3. In the window that appears select Installed > Templates > Visual C# > Windows Store.

  4. Select the Blank App (XAML) template.
  5. Enter a Name for your project. This is the name of your project directory and the name visible in Visual Studio’s Solution Explorer.

ANDROID HINT

Solution Explorer is similar to Package Explorer in Eclipse.

 

  1. Select a Location for your project. This is where your source files will be stored on your local disk.

ANDROID HINT

This is similar to a Workspace used by Eclipse.

 

  1. Enter a Solution name. Solutions are how Visual Studio organizes multiple projects. Be default Visual Studio will use your project’s name as the solution name.
  2. Click OK.

 

You may have noticed that Visual Studio has quite a few project templates for you to select from. Here’s a brief description of each template:

  • Blank App (XAML) – A single-page project for a Windows Store app that has no predefined controls or layout. This is the template you used for your project.
  • Grid App (XAML) – A three-page project for a Windows Store app that navigates among grouped items arranged in a grid. Dedicated pages display group and item details.
  • Split App (XAML) – A two-page project for a Windows Store app that navigates among grouped items. The first page allows group selection while the second displays an item list alongside details for the selected item.
  • Class Library (Windows Store apps) – A project that creates a managed class library for Windows Store apps or Windows Runtime components.
  • Windows Runtime Component – A project for a Windows Runtime component that can be used by Windows Store apps, regardless of the programming languages in which the apps are written. (More on that in a moment)
  • Unit Test Library (Windows Store apps) – A project that contains unit tests that can be used to test Windows Store apps, Windows Runtime components, or class libraries for Windows Store apps.

     

For the sake of this walkthrough you’ll be using a combination of XAML and C# to create your first Windows Store app. XAML (eXtensible Application Markup Language) is nothing more than a declarative language used to create the UI for Windows Store apps. If you’ve done any Android UI development you’ll be very comfortable with XAML as it is simply an xml file. Just to be clear you are not limited to XAML and C# for your apps. You could use a combination of XAML and Visual Basic, XAML and Visual C++, or HTML and JavaScript to create your app.

Your Windows Store project is now set up with some default files and you’re ready to being building your app. In the next lesson you’ll spend some time exploring the project you just created.

Previous Posts in this Series

  1. Setting up the Development Environment

Additional Resources

Over the past several weeks I’ve been working on some content I’m excited to finally share with you through a series of blog posts. This series will introduce you to Windows 8 development from an Android developer’s perspective. Through the course of the series you’ll create your first app. It won’t be anything pretty, but you’ll learn the ins and outs of the development environment, how to create a simple user interface, and how to perform navigation. Along the way you’ll see some Android Hints that will help make it easier for you to transition your existing skills to the Windows platform. You’ll also see some Visual Studio Tips to make you more productive in your development environment. Good luck!

Your first task when it comes to Windows 8 development is getting your development environment up and running. It’s a three step process:

Install Windows 8

You can’t create Windows Store apps on anything but Windows 8. You have several options. If you’re running a Windows 7 machine, you can either upgrade your existing install, create a separate partition for you Windows 8 install, or create a bootable vhd with Windows 8. If you’re running Max OS X you can use Boot Camp to create a Windows 8 partition for dual booting, or you can use software like Parallels to run a Windows 8 VM inside of OS X. On a Mac I prefer Parallels as it allows me to easily move back and forth between a Windows and Mac environment. If you go down this road make sure you have plenty of RAM on your machine. My MacBook Air has 8 GB of RAM and it works well for me.

Install Visual Studio Express 2012 for Windows 8

Download and install Visual Studio Express 2012 for Windows 8 from http://aka.ms/getvs12now. Visual Studio is the IDE, similar to Eclipse, that you’ll use for creating Windows Store applications. Please note, there are a five Visual Studio Express products available. Make sure you download and install the one specifically for Windows 8.

There are two options for installation, a web installer and a disk image. A description of each is below, choose the one that works best for you:

  1. Web Installer – this is a small initial download that will download the necessary components during the installation process. Download at http://bit.ly/XLyHZ5.
  2. Disk Image (iso) – This is the full installer, no additional downloads are required. Download at http://bit.ly/YdGiz4.

Get a developer license for Windows 8

A developer license lets you install, develop, test, and evaluate Windows Store apps before the Windows Store tests and certifies them. Licenses are free, acquisition is automatic and you can acquire as many as you need. You will need a Microsoft account to obtain your developer license. You can read more about Microsoft accounts and sign up for one, if you don’t already have one, at http://bit.ly/Nt0efj. Getting the license is easy. The first time you run Visual Studio 2012 on your development machine you will be prompted to obtain a developer license. Developer licenses expire every 30 days, and Visual Studio will prompt you to renew your developer license if it has expired.

That’s it! You’re good to go. In the next lesson you’ll learn how to create your first Windows Store project.

Additional Resources

 

tips word in wood type

If you’re building a Windows Store app that plays audio you have the option of being able to play your app’s audio in the background (i.e. when the app is not running). Over the course of three posts I want to share some tips and tricks you can use for enabling your apps to run audio in the background and make it through the Windows Store certification process.

In this post I’ll show you how to enable background audio in your apps. Essentially there are two things you need to do. First you’ll need to add the capability to your application’s manifest. These can be done via the following steps:

  1. Open your application’s manifest (that’s the Package.appxmanifest file)
  2. Click on the Declarations tab
  3. Select Background Tasks from the Available Declarations drop down and click Add
  4. Check the Audio checkbox and enter either an Entry point or Start page

image

This will result in the following being added to the xml of the manifest

You need to do one more thing in order to make it work. You’ll need to find the MediaElement that will be playing the audio and set its AudioCategory to BackgroundCapableMedia. If you’re doing so in XAML it will look like this:

Congratulations! Your app can now play background audio.

Warning! Your app will not pass certification…yet. To get into the store your app will need to register for media transport controls as well as consider handling sound level notification events. More on those in upcoming posts.

Additional Resources:

Spyhouse Office Hours

March 6, 2013

coffeeshop_coders

Just a reminder that next Wednesday I’ll be holding office hours from 11:00 AM to 1:00 PM at Spyhouse Coffee in Uptown. This

isn’t anything formal you have to sign up for, there are no presentations, just feel free to drop by and chat.

If you’re the kind of person that needs to get this on your calendar or you won’t remember and/or show up, you can do so here.

You can see my full list of Spyhouse Coffee office hours here.

I hope to see you there!

What’s that you say? You haven’t even start writing your Windows 8 app? No worries! Here’s a couple of great resources to help you on your way:

  1. Download Visual Studio Express 2012 for Windows 8 – it’s free!
  2. Sign up for the 30 to Launch program for great tips and tricks

help_chalkboard

Next Monday I will be holding office hours from 1:00 PM to 3:00 PM at the Microsoft Store at the Mall of America. I will be there to help you take your Windows 8 app from an idea in your head to a killer app in the Windows Store. This isn’t anything formal you have to sign up for, there are no presentations, just feel free to drop by and chat.

If you’re the kind of person that needs to get this on your calendar or you won’t remember and/or show up, you can do so here.

The Microsoft Store is on level 1 of the Mall of America next to Lego, across from Guest Accessories. You can get more information on the store here.

You can see the full list of upcoming office hour events here.

What’s that you say? You haven’t even start writing your Windows 8 app? No worries! Here’s a couple of great resources to help you on your way:

  1. Download Visual Studio Express 2012 for Windows 8 – it’s free!
  2. Sign up for the 30 to Launch program for great tips and tricks

tips word in wood type

Do you want to really impress the users of your Windows Store applications with a single line of code? If you answered yes, and I’m assuming you would, then read on. If you answered no, well, then, I don’t really know what to say, but I would encourage you read on as well.

One of the cool features in Windows 8 is the Search charm. This allows you to search across the system and within apps to find exactly what you’re looking for. As developers we can leverage this by implementing the Search contract. This contract allows you to add a search pane to your apps that enables users to search within your app both while the app is running as well as from anywhere in the system. Adding the search capability is fairly straightforward and I have some links at the end of this post that can get you on your way. However, if you follow the tutorials you will be left with a suboptimal implementation. Your apps will have a search, but the user will have to activate the Search charm either by using the mouse and dragging the cursor to the upper or lower right hand corner, by using touch and swiping from the right edge of the screen, or by using the keyboard shortcut (Windows Key + Q). This is how the native Windows Store, Music, and Video apps implement search today. While all of the options work, it’s one extra thing the user has to do when what he or she really wants to do is search. Instead, wouldn’t it be better if search would just start when the user starts typing on the keyboard (either a physical keyboard or the onscreen keyboard)? Well you can with just one line of code. Here it is:

I know, I just blew your mind right?! Hope it helps!

(Yes, I know the gist has more than one line of code in it, but I wanted to put it context of where you would use it. In this case I wired it into the OnNavigatedTo event of a page.)

Resources for adding Search to your Windows Store apps:

Weekly Windows 8 Office Hours

February 25, 2013

help_chalkboard

Next Monday I will be holding office hours from 1:00 PM to 3:00 PM at the Microsoft Store at the Mall of America. I will be there to help you take your Windows 8 app from an idea in your head to a killer app in the Windows Store. This isn’t anything formal you have to sign up for, there are no presentations, just feel free to drop by and chat.

If you’re the kind of person that needs to get this on your calendar or you won’t remember and/or show up, you can do so here.

The Microsoft Store is on level 1 of the Mall of America next to Lego, across from Guest Accessories. You can get more information on the store here.

You can see the full list of upcoming office hour events here.

What’s that you say? You haven’t even start writing your Windows 8 app? No worries! Here’s a couple of great resources to help you on your way:

  1. Download Visual Studio Express 2012 for Windows 8 – it’s free!
  2. Sign up for the 30 to Launch program for great tips and tricks
  3. Sign up for the XBOX Ultimate Experience contest as a little extra motivation to get you app in the store