How to start Application on Windows Phone Remotely

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

First class you have to be aware of is DatastoreManager, which helps you to deal with embedded platforms. This class is implemented in assembly Microsoft.SmartDevice.Connectivity.dll,
which is installed in GAC. If you need to reference it please look somewhere in some of VS folders.

DatastoreManager manager = new DatastoreManage(CultureInfo.CurrentUICulture.LCID);

One of most interesting methods is GetPlatforms. When I execute it on my test machine I get following result:

manager.GetPlatforms()

Count = 1
    [0]: {Windows Phone 7}

Each platform is specified by its name and GUID. For example Windows Mobile 5 has a GUID "BD0CC567-F6FD-4ca3-99D2-063EFDFC0A39". Windows Phone 7 platform has a GUID {E6B29E6-AAE1-41dc-9849-049507CBA2B0}.
If you know the GUID you can instantiate the platform explicitly:

Platform p = manager.GetPlatform(new ObjectId(new Guid(“E6B29E6-AAE1-41dc-9849-049507CBA2B0”));

You might ask yourself why this can be important? Well, if you have a platform instance you can enumerate devices:

foreach (Device device in platform.GetDevices())
{

        device.Connect();        

        . . .        

        device.Disconnect();

}


Then, you can connect to device, perform some actions and close connection.
Next example shows how to enumerate all applications at device (only installed by you!) and how to start them.

ICollection<RemoteApplication> apps = device.GetInstalledApplications();
foreach (var app in apps)
{
    app.Launch();
}

In other words, you connect your phone by USB cable to your machine. At the machine you can start this code and all installed apps will be
lunched at the device.

By using of device instance you can do much more funny things Smile like install or delete some app and more.

For example, if you know the ID of application which is build in (not installed by you) you can also start it. Good examples of such apps are
all launchers and chooser.

For example next snippet shows how to launch camera task:


var cameraLauncher = device.GetApplication(new Guid("5B04B775-356B-4AA0-AAF8-6491FFEA5631"));

cameraLauncher.Launch();

Because every app at the phone has an ID (defined in WMAppManifest.xml) it can be accessed by device instance. Please don’t ask me how I found all those GUID-s Smile


Posted Jan 29 2011, 12:28 PM by Damir Dobric
developers.de is a .Net Community Blog powered by daenet GmbH.