software you can take with you

Peter Foot

Microsoft Windows Phone Development MVP
  • Charming ApplicationModel

    My previous couple of posts have been related to the Sharing functionality provided by the Charming libraries. This one looks at a smaller (but no less exciting) component. For Windows Phone development if you want to retrieve the app information at runtime you have to read the WMAppManifest.xml file included in the package. In Windows 8 an API was provided (Windows.ApplicationModel.Package and related classes) to provide a strongly typed API around the Windows Store metadata. Although these classes are present in Windows Phone projects they aren't all implemented and you can waste a lot of time getting exceptions assuming that the functionality will work.

    Enter Charming ApplicationModel. This replicates the same object model you see for Windows Store apps but in a way which actually works and reads information from the xap. In addition to this there is an added property - Capabilities which returns the combination of capabilities requested by your package. This has been especially useful in developing the other Charming libraries as it makes it possible to add functionality only when certain capabilities are added in the consuming app. For example you won't get any nasty surprises if you add the Share library and not the Proximity capability - the library won't include the "Tap+Share" option.

    Beyond the other Charming libraries you can use this library yourself - for example write a generic About page which is populated at runtime by the app metadata. The library is tiny, you won't need to mess about with XML parsing and it gives you the potential of sharing more code between Phone and Store projects.

    ApplicationModel is the only one of the Charming libraries which doesn't expose any UI. As already stated it is used by Charming Share, and also Charming Settings and as of 8.1 it will also be used by Charming Search but more of that in the next post...

  • A Trip Around Charming Share

    The Charming libraries for Windows Phone are a set of (currently) six components for Windows Phone development with the mission of providing more code consistency with Windows 8. Following on from the NFC component, this post will cover its cousin the Share component.

    Windows Phone provides a number of classes in the Windows.ApplicationModel.DataTransfer namespace but there is no Share charm or sharing functionality here. The Charming Share library replicates this functionality with a sharing component which can be called in the same way as on Windows 8 and yet exposes the various platform sharing mechanisms. Because this is not an OS feature it is not possible to create share targets and share data with other apps. I am looking at the possibility of making the providers extensible so that you can add items to the list of targets.

    You can currently share three types of object - Text, Uri and Image. The available targets will vary depending on the data you pass. Image is a special case as it uses the ShareMediaTask which means you have access to all the system targets including other apps registered as Photo Extras. This also means you can share an image via Email which is not possible with the EmailComposeTask. The table below shows the supported targets based on data type:-

     

    Text

    Uri

    Image

    Tap+Send

     

    Yes

    Yes

    Bluetooth

     

     

    Yes

    Messaging

    Yes

    Yes

    Yes

    Email

    Yes

    Yes

    Yes (Individually Listed)

    Social Networks

    Yes

    Yes

    Yes (Individually Listed)

    Photo Extras

     

     

    Yes

     The Tap+Send functionality for Uris is provided by the separate Charming NFC Share component. It will only appear in the list if you add the NFC library as a reference in your project (and add the Proximity capability). The share dialog shown when passing a Uri is designed to look familiar and uses page transitions from the Phone Toolkit:-

    I'm working on localised resources for these components so that they will be supported in all Windows Phone 8 languages. Because the Image sharing dialog is system provided this is already localised into the device language. In early testing the NFC and Share components are looking good with localised text and supporting LeftToRight and RightToLeft layouts.

    If other formats can be supported I'm looking at the possibility of adding a Bluetooth provider to beam files using OBEX, again trying to stick as closely to the system provided Bluetooth sharing for images. Another possible target is a Clipboard provider for Text or Uri, the source code is in there but the provider is not currently used.

  • Introducing Charming NFC Share

    In my talk this week I demonstrated a simple library for sharing a single Uri over NFC. I've now completed packaging it up and it is available on NuGet - https://www.nuget.org/packages/InTheHand.Phone.Nfc/

    This is a very simple component to use in your app requiring just three lines of code to call. It requires the Windows Phone Toolkit from which it uses page transitions, if you don't already have this in your project NuGet will add it for you. It also requires you to add the Proximity capability in your app metadata. The Windows Phone Emulator exposes a null NFC device so it is possible to interact with this feature on the emulator (it just won't send anything). The look and feel of the task has been designed to match the platform so it will look instantly familiar and supports both the light and dark themes.

    To share a Uri from your app you'll need to execute the following:-

    Add the InTheHand.Phone.Nfc package via NuGet

    Add the ID_CAP_PROXIMITY capability to your WMAppManifest.xml

    Add the following code when you want to share a Uri:-

    InTheHand.Phone.Tasks.ShareNfcLinkTask snlt = new InTheHand.Phone.Tasks.ShareNfcLinkTask();

    snlt.LinkUri = new Uri("http://peterfoot.net");

    snlt.Show();

    
    

    Obviously setting the LinkUri to whatever URI you want to share. This could be a web link or a custom URI which performs some task in your app.

    At the moment the resources in the library are not localised beyond English although I hope to add this soon.

    This is the first in a set of related "Charming" libraries for Windows Phone. I'll be adding more to NuGet shortly. Hopefully the reason for the name will become clearer too...

  • Resources from Bluetooth and NFC for Windows Phone and Beyond

    As promised here are the resources from yesterday's session on Bluetooth and NFC. I've begun uploading the slides and code to this SkyDrive folder:-

    http://sdrv.ms/143OZD7

    I have a few finishing touches to put on the sharing library for NFC - it will be up on NuGet and CodePlex shortly.

     

  • Page Header Styles

    The page header is the small text you see across the top of most apps, often in all uppercase. When you create a new Windows Phone app from the default templates you'll get something like this created in your MainPage.xaml

    <TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>

    The annoying thing about this is this is not the same format as built-in apps. The font size is wrong and so is the weight. Rather than manually fixing up every instance I define the following style in the App.xaml:

    <Style x:Name="PhoneTextPageHeaderStyle" BasedOn="{StaticResource PhoneTextNormalStyle}" TargetType="TextBlock">
       <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}"/>
       <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}"/>
    </Style>

    Then my page XAML becomes:-

    <TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextPageHeaderStyle}"/>

    My app is now consistent with built-in apps!

    [Updated with simplified Style XAML removing hard-coded font size]

  • Update to 32feet.NET for Windows Phone

    Version 8.1 of 32feet.NET for Windows Phone is now available via NuGet. This package adds some helper functionality for Bluetooth development. In particular this version includes the RfCommServiceId (designed to match the Windows 8.1 API) to provide information about various standard RfComm profiles. You can use this when connecting a StreamSocket or to filter devices in the BluetoothDevicePicker.

    Speaking of which the BluetoothDevicePicker has been updated to more closely follow the appearance of the dialog displayed when you use the built in Bluetooth photo sharing feature. Currently the library is built with localized resources in mind but has only English text. If you are interested in providing localized text in your own language please contact me.

    The CodePlex project contains the source and the Serial sample app. I'm working on some additional sample apps which will be added soon.

  • Sending an Email with an Attachment on Windows Phone (Sort of)

    From it's initial release Windows Phone has had a method to programmatically send an email from code. In keeping with the mantra that the user is in control it has always been a method to populate the email but allow the user to decide to modify, send or cancel. Despite much demand the ability to attach files has not been made available. As a user you can attach a picture to an outgoing email but the phone can receive a wider variety of types. There is, albeit not as obvious, a method to send a picture attachment via email but there are caveats.

    The ShareMediaTask only allows you to specify the image to use and not the transport to send via or an accompanying message. In fact it basically is just running the "share..." menu found in the built in Pictures app. The other caveat is that the picture must be in a location that the system can read from so a path to your isolated storage won't work. You can however copy an image to the user's pictures library. Another annoyance is that once you've copied a picture to the library you can't delete it - only the user has the ability to do this.

    Microsoft.Xna.Framework.Media.MediaLibrary ml = new Microsoft.Xna.Framework.Media.MediaLibrary();
    Microsoft.Xna.Framework.Media.Picture pic = ml.SavePicture("mypic.png", stream);
    path = Microsoft.Xna.Framework.Media.PhoneExtensions.MediaLibraryExtensions.GetPath(pic);

    The above code takes an image stream and placed it in the library and gets a true file path. The code to initiate the share operation is equally simple:-

    Microsoft.Phone.Tasks.ShareMediaTask shareMediaTask = new Microsoft.Phone.Tasks.ShareMediaTask();
    shareMediaTask.FilePath = path;
    shareMediaTask.Show();

    That's all there is to it - you don't get any feedback on what option was chosen (or whether the operation was cancelled).

    I'll be discussing some more around sharing various types of data at my talk on this coming Tuesday for WPUG Manchester which is titled "Bluetooth and NFC for Windows Phone and Beyond" where I'll be unveiling some ways to make "Charming" apps for Windows Phone.

  • Deployment Parts in a Windows Phone App

    My apologies in advance as this is a little bit of an obscure scenario but I thought I'd share this information in case others found it useful.

    Imagine if you will the following scenario. You have a dll project which can make use of other "provider" libraries. These are optional and the main dll should function regardless of whether the provider is present or not. The issue is this - you need to detect from your library whether this provider dll is present at runtime. In traditional .NET you would use reflection but not all aspects of this are available in the Silverlight model. Instead there is a way to interrogate all the assemblies within the XAP from the Deployment class. The following code snippet shows how to check for a particular assembly:-

    bool featurePresent = false;

    foreach (System.Windows.AssemblyPart part in System.Windows.Deployment.Current.Parts)
    {
       if (part.Source.ToString().Contains("FeatureAssemblyName"))
       {
          featurePresent = true;
          break;
       }
    }

  • Installing Windows 8.1 Preview onto a UK Surface RT

    It soon became clear that the Preview update package supports only a small subset of languages and while US English is of course supported the update would refuse to install on a device running UK English.

    I first followed these instructions to install the update package:-

    http://www.intowindows.com/the-update-is-not-applicable-to-your-computer/

    This worked and enabled the Store item to upgrade but that itself would not work because of the language issue. I then found this answer on the forums with a solution. It requires editing the registry so use it at your own peril:-

    http://answers.microsoft.com/en-us/windows/forum/windows8_1_pr-windows_store/the-windows-81-preview-isnt-available-right-now/274c3506-19f8-4bc1-ae32-9f35e855915b

    After this (reboot required) I was able to start the update process. It requires a 2GB+ download so took a while followed by quite a lengthy install but has now completed and I'm running 8.1. After the update I was able to set the keyboard language back to UK English, but you can't set it as your primary display language because there is no UK English language pack in the preview. This isn't a big problem as I'm already used to working regularly with US spellings.

  • Bluetooth Development with Windows 8.1

    Unless you've been stuck under a rock (in which case what are you doing reading this?) you'll know that Microsoft announced a preview release of Windows 8.1 at Build yesterday. While I haven't got a development machine up and running yet (No easy upgrade if your device is UK English) I've been looking at the updated documentation at MSDN. Of the many new APIs described there are a couple of new namespaces which will be interesting to those working with Bluetooth devices:-

    Windows.Devices.Bluetooth.GenericAttributeProfile - Contains functionality to work with Bluetooth LE devices. This will make it possible to interact with devices such as FitBit and other low energy sensors and devices from within apps - which means support on ARM devices.

    Windows.Devices.Bluetooth.Rfcomm - Support for normal serial sockets Bluetooth. While completely different from the Windows Phone 8 API it provides the same functionality and more. Ability to enumerate and get notified of device arrival and departure and access to SDP attributes. There are identifiers for a number of standard profiles - Generic File Transfer, ObexFileTransfer, ObexObjectPush, PhoneBookAccess (client and server), SerialPort (SPP).

    A new Chat sample is available for 8.1 here - http://code.msdn.microsoft.com/windowsapps/Bluetooth-Rfcomm-Chat-afcee559

  • Moving from WinForms to XAML Runtime on Windows Embedded Compact

    I recently found an old set of slides I created for TechEd NZ a few years ago which collected together useful information for moving from Windows Mobile to Windows Phone. It struck me that some of this would also be useful for the Embedded XAML Runtime when considering moving code from a traditional WinForms UI to a XAML based UI using Xaml In The Hand. I've modified the table listing controls in both UI worlds and added it to the Knowledge Base here:-

    http://inthehand.uservoice.com/knowledgebase/articles/209986-winforms-versus-xaml-runtime-controls

    While most of this still applies to Windows Phone (and with a few further changes Windows Store apps) there are items here which are specific to Windows Embedded Compact - The ComboBox control which doesn't exist on Phone (although there is a perfectly good alternative), and the MediaElement and WebBrowser controls which don't exist in the XAML Runtime but for which we have created managed code controls which expose the same XAML and C# interfaces.

  • NFC Text tags on WinRT

    To follow the last post I thought I would quickly round it off by looking at the code required to listen for tags on a Windows 8/RT device. Devices with NFC built in are like hens teeth but one such RT device exists in the Asus VivoTab RT. Because it's an RT device that means running the Remote Debugger and doing the development on a separate Windows 8 PC. The problem with the Windows 8/RT experience is it is not as set in stone as Windows Phone and so issues like this occur (http://social.msdn.microsoft.com/Forums/en-US/tailoringappsfordevices/thread/9da68387-e0cb-4e02-ac71-bad61f6ff7c6) where some devices don't correctly advertise support for all tag types. The good news with the Asus is that it does support subscribing to NDEF messages and you can use the same code as in my previous Windows Phone example to read a Text tag. The same Ndef library is used as this supports both Windows 8/RT and Windows Phone 8.

    One thing which is a little frustrating when remote debugging is that you have to register for a developer license on the tablet before the debug session will continue. So even though you have a license on your development machine you also need one on the tablet (despite the fact you can't actually compile an app on it). There doesn't seem to be a limit to how many devices you can register for a license using your Microsoft ID so this shouldn't become a problem. You will find that you have to renew it regularly though...

    In a future post we will delve into other tag types...

  • NFC - Simple text tags on Windows Phone

    This article follows on from the last post on NFC to dig a little deeper on Windows Phone and Windows 8 (both of which share the same APIs for NFC).

    Requirement or just Capability

    In Windows Phone you have to add the ID_CAP_PROXIMITY capability to your app to use NFC. What about the ID_REQ_NFC requirement? Well the difference here is that when you specify a requirement the app will only be made available to devices with that feature. Whether you use the requirement therefore depends on whether NFC is core to your application or is an optional feature. This means it is valid to submit an app with NFC capabilities to devices which don't have the hardware. Therefore you must always check first if

    ProximityDevice.GetDefault() == null

    Types of NFC Message

    So you've got as far as calling the SubscribeForMessage API to listen for NFC messages, if you check the help file for this function you'll see it refers to the partner method "PublishBinaryMessage" to document the message types supported. Then you look down the list of supported protocols and your heart sinks! It's a long list and there seems to be a lot of duplication - why when we have the NDEF standards are there Windows versions too? Which ones can I use across different platforms? Not to mention the fact that you can't subscribe to all of these message types on Windows Phone so the utopia of a shared NFC API across both Windows APIs is shattered.

    The good news is that the Windows message types are actually helpers over the top of NDEF types and are designed to simplify reading those message types, we'll look into those on Windows 8/RT at a later stage. There is a very good NDEF library on CodePlex (and NuGet) to parse standard NDEF records. For example the way to read a plain text NDEF.Text message is actually using the NDEF message type because the API doesn't provide a subtype specifically for Text tags. When the tag is tapped you'll receive a message payload which you can parse with the NdefLibrary.Ndef.NdefMessage class.

    private void MessageReceived(ProximityDevice device, ProximityMessage message) 
    {
    NdefLibrary.Ndef.NdefMessage.FromByteArray(message.Data.ToArray());
    
    string s = System.Text.Encoding.UTF8.GetString(msg[0].Payload, 0, msg[0].Payload.Length).Substring(2);
    }
    

    The final thing you'll notice from the received text is that it contains the two-character language code at the beginning. Note that there is no error checking in the above sample and it assumes that the text tag is the first record in the message. You can see from the NdefMessage class that it contains a collection of records which can be of a number of specific types. More to follow as we delve deeper...

  • Cross Platform NFC

    NFC support in Windows Phone provides an exciting new way to add interactivity to apps and games. This series of posts will look at the state of NFC across the Windows and Android platforms. There are a number of standard Tag types defined by the NDEF format, for the sake of simplicity we’ll ignore the fact that Android can read other tag types and just concentrate on NDEF as it provides the best interoperability. Representing Windows Phone 8 I’m using the Nokia Lumia 920 although the 820 Developer phone provides the same experience. Representing Windows 8/RT is the Asus VivoTab RT which is one of few tablets with NFC support built in. Representing Android is the Samsung Galaxy S3. Since I’m less familiar with Android there is a possibility that some of the functionality I have discovered is Samsung specific and not part of the core Android OS.

    Sending

    The first table here shows the formats for which sending is supported within the platform. I haven’t included app links as these are platform specific. I was disappointed to find that out of the box the Windows tablet has no capability to share items over NFC from the built in apps. The send behaviour on Android is very seamless – tap the device against another and if the current app can share the screen changes slightly and you tap to share the current item. On Windows Phone you have to go through a few layers of menu first before being prompted to tap a device.

     

     

    Windows Phone

    Windows 8/RT

    Android 4.1

    Uri

    Yes

    Yes

    Yes

    Mime (vCard)

    Yes

    Requires 3rd Party App

    Yes

    Text

    No

    No

    No

     

    Receiving

    The platforms can receive over NFC so long as the device is not pin locked. The following list shows what types of data (or pre-written tags) you can read on these devices without any specific third-party apps running.

     

    Windows Phone

    Windows 8/RT

    Android 4.1

    Uri

    Yes

    Yes

    Yes

    Mime (vCard)

    Yes

    Yes

    Yes

    Text

    No

    No

    Yes

     

    So from a very high level the three platforms support the basic tag types for Uris and Contacts across the board. Although Android has default behaviour when receiving a Text tag it just displays the text on screen – there is no functionality to do anything with the text. In a future investigation I’ll look into the tag types in more detail. The Uri tag for example is very powerful because you can register custom Uri schemes for your app so that a Uri tag could provide a deep link into your application. The systems maintain support for well-defined Uri schemas like http, tel and sms for example. There are additional platform specific ones on Windows Phone for launching items such as Wifi and Bluetooth Settings pages.

  • Use Team Foundation Service for Embedded Projects

    Microsoft's hosted TFS (http://tfs.visualstudio.com/) provides a cloud hosted TFS project collection which is free for small teams. It works neatly with VS2012 which is fine for Windows Store and Windows Phone project types but for .NET Compact Framework development we are still stuck with using Visual Studio 2008. Luckily with a few patches it is possible to connect to a Team Foundation Service collection from Visual Studio 2008. I recently had to rebuild my Windows 8 desktop machine so for reference thought I would blog the instructions for setting this up. You'll need to install the items in the following order:-

    No before you ask I didn't make up the name of that last one, I actually shortened it for you :-)

    To open a project from the server open your shiny up-to-date VS2008 IDE and go to File > Source Control > Open from Source Control. You'll get a blank dialog with a drop down box for servers and an empty list of projects. Select the Servers... button and then click Add..

    You'll notice that after these updates the dialog allows you to enter a fully formed Url for the server and will grey out the connection details below. You must specify https and include the DefaultCollection indicator, this Uri will always be of the form <yourchosenname>.visualstudio.com. When you click okay VS2008 will connect to the service and then prompt you to authenticate with your Microsoft ID. Once this is successful you'll see the following:-

     

    It will show you the display name of the account you are logged in as at the bottom left (not on this shot) and a Sign Out option. Things get a little complicated if you regularly use different Microsoft IDs because you can get into a situation where VS2008 shows error messages from the service but doesn't show what account it thinks you are logged in as or give the option to log out and back in with different credentials. Still haven't found a neat way around this yet other than making sure you log out from your Microsoft ID in your browser and possibly also the browser within the VS shell. It seems to be a cookie issue and possibly compounded if you use a Windows 8 account signing in with your Microsoft ID. If you've successfully got to this step you can select a project, assign a local path and work as you would with a local TFS back end. As well as the source control the work items sync back and forth with the web front end. I don't think there is any capability to use the "Preview" build services for Embedded projects and doubt if this functionality will be added.

More Posts « Previous page - Next page »
Copyright © 2001-2013 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy. OrcsWeb's Windows Cloud Server Hosting