WP7 Isolated Storage Snapshots

 

When working with Isolated Storage on the phone you sometimes have difficulty “seeing” what is located in the IsoStore for your application.  Luckily we have a tool that will help you take snapshots of the Sandboxed Isolated Storage for your application.  It is a command line tool called ISETool.exe and it is located in:

(for 32 bit os) c:\Program Files\Microsoft SDKs\Windows Phone\v7.1\Tools\IsolatedStorageExplorerTool

(for 64 bit) c:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.1\Tools\IsolatedStorageExplorerTool

To run the tool, bring up a command line and change the directory to the location above.

 

image

Then run the ISTool.exe with the following parameters

◦ts – take snapshot  (rs for restore)
◦xd – emulator
◦guid – product GUID from WPAppManifest.xml
◦desktop dir – where to copy the isolated storage files

image

 

It will download the contents of your Isolated Storage for that application to the folder you specified

image

 

You can also restore to the phone or emulator by doing the reverse.

ISETool.exe rs xd 11111111-2222-3333-4444-555555555555 “C:\snapshots\IsolatedStore”

 

This can also be used for local databases as well as restoring your environment to a specific state.  Let me know if you have any questions.

 

Camera Picture by Capt Kodak flickr cc

Windows Phone Alerts and Reminders

Another great feature for Windows Phone Mango is the ability to set up reminders and alerts in your application (While it is not running).  You would be surprised how many applications want/need this. During our Windows Phone 7 Unleashed events this was a recurring topic. 

The great part is that it is really simple.

 

 

imageFor this application, we are creating a very basic interface.  A text box for the title, a text box for the reminder message and a button that says “remind me”.  In addition, there is a label to hold the parameter that is sent back from the reminder.

The first thing you want to do once you build the UI is to click on the Remind Me button to create the click event for the button and add the following code to the event.

 private void OnRemindMeClick(object sender, RoutedEventArgs e)
        {
            Reminder r = new Reminder("reminder"); 
            r.Title = txtTitle.Text; 
            r.Content = txtContent.Text; 
            r.BeginTime = DateTime.Now.AddSeconds(10); 
            r.NavigationUri = new Uri("/MainPage.xaml?reminder=" + 
txtContent.Text ,UriKind.Relative); ScheduledActionService.Add(r); }

All we need to do is :

  • create an instance of the reminder
  • Set the title and content to the text boxes text property
  • set the begin time (in this instance I am doing it in 10 seconds from now)
  • Set the NavigationUri (this is where you will return when a user clicks on a message)
  • Add the reminder to the ScheduledActionService

Notice that we are passing the txtContent.Text back to the program when the user replies.  This can be userIDs, itemIDs, etc… .  Whatever makes sense for your program.

To capture the returning data, add this to an onNavigatedTo override.

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            string param = null;
            if (NavigationContext.QueryString.TryGetValue("reminder", out param))
                Param.Text = param;

            if (ScheduledActionService.Find("reminder") != null)
                ScheduledActionService.Remove("reminder");

        }

We collect the reminder parameter from the Querystring and set it equal to our Param.txt . Notice that we are also removing the reminder from the service.  In the way ours is constructed, if the user clicked on it a second time it would try to add “reminder” a second time which is not allowed.

There you go…. easy as pie Smile

 

(Clock picture from “H is for Home on Flickr” Creative Commons)

Background Agents in WP7

With the release of Windows Phone 7 Mango, you now have the ability to multitask (scheduled multitask) by using background agents.  Background agents allow you to do things when your application is not running. 

 

It is important to understand that the OS is responsible for determining when your background agent can run and is determined by a number of factors. It is also dependent on the type of Background Agent you use.

 

For both types of Agents you are constrained by the following :

Periodic Agents (PeriodicTask) are used when you want a “seimi” predictable action to fire.  But they are constrained to the following. For example, you can use Periodic Agents for collecting quick GPS coordinates or updating an RSS feed.

  • 30 Minute Intervals (this time may drift)
  • Run for 25 seconds
  • Might not run on Battery Saver mode
  • Agents per device (The number of apps using agents) can be as low as 6 on some devices

Resource-intensive Agents (resourceIntensiveTask) can be used for more intensive items like downloading larger files or coping database entries to a replication server. But you must keep in mind that they have some specific constraints as well.

 

  • Duration 10 Minutes
  • External Power Required (You need to plug it in)
  • Connection through WiFi or PC
  • Battery 90% or better
  • Screen Lock on
  • No active phone call

What this means is that it MAY never run.  The best case scenario is the user will have their phone connected to their WiFi when they plug it in at night.

But …. after all of that, it is pretty easy to use.  All you need to do is

  • Add a ScheduledAgentTasks project to your solution
  • Add a reference to the agent project in your phone application project
  • Add your code to the Invoke Method in the ScheduledAgentTasks project as shown below

 protected override void OnInvoke(ScheduledTask task)
        {
            //TODO: Add code to perform your task in background
            string toastMessage = "";

            // If your application uses both PeriodicTask and ResourceIntensiveTask
            // you can branch your application code here. Otherwise, you don't need to.
            if (task is PeriodicTask)
            {
                // Execute periodic task actions here.
                toastMessage = "Periodic task running.";
            }
            else
            {
                // Execute resource-intensive task actions here.
                toastMessage = "Resource-intensive task running.";
            }

            // Launch a toast to show that the agent is running.
            // The toast will not be shown if the foreground application is running.
            ShellToast toast = new ShellToast();
            toast.Title = "Background Agent Sample";
            toast.Content = toastMessage;
            toast.Show();

            // If debugging is enabled, launch the agent again in one minute.
#if DEBUG_AGENT
  ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(60));
#endif

            // Call NotifyComplete to let the system know the agent is done working.
            NotifyComplete();
        }

 

The one caveat is that it can sometimes be difficult to debug in an emulator.  If you have a developer phone you will have a much easier time debugging it on the device.  If you have any questions, let me know.

Windows Phone testing for sensors

If you are planning on using the new sensors that are in the Windows Phone code named Mango (Gyroscope, Compass, etc…), you need to add some code to your application to test and see if they are available.  You can use the Microsoft.Devices.Sensors namespace to find this out.

 

bool IsGyroSupported = Microsoft.Devices.Sensors.Gyroscope.IsSupported;

bool IsAccelerometerSupported = Microsoft.Devices.Sensors.Accelerometer.IsSupported;

bool IsCompassSupported = Microsoft.Devices.Sensors.Compass.IsSupported;

bool IsMotionSupported = Microsoft.Devices.Sensors.Motion.IsSupported;
 
The Motion Sensor is the API that combines all the other sensors and adds some math to
make it easier to build your application using sensors.

Get Network Info on Windows Phone

When you are developing your application, you keep in mind that you may not always have a network connection. You should prepare for this simi-connected environment.  To do this, you should use the Microsoft.Phone.Net.NetworkingInformation namespace. With this you can do things like, check to see if the network is available, determine the type of network the phone is using (CDMA, GSM), or find the MO (Mobile Operator)

bool IsConnected =
Microsoft.Phone.Net.NetworkInformation.DeviceNetworkInformation.IsNetworkAvailable;
  
string MobileOperator = 
Microsoft.Phone.Net.NetworkInformation.DeviceNetworkInformation.CellularMobileOperator;
 
bool IsCellularDataEnabled = 
Microsoft.Phone.Net.NetworkInformation. DeviceNetworkInformation.IsCellularDataEnabled;
          
bool IsCellularDataRoamingEnabled = 
Microsoft.Phone.Net.NetworkInformation DeviceNetworkInformation.IsCellularDataRoamingEnabled;
 
bool IsWifiEnabled =
Microsoft.Phone.Net.NetworkInformation. DeviceNetworkInformation.IsWiFiEnabled;

 

The NetworkInterfaceType is another good one to put to determine what type of speeds you are going to get.

WP7 Getting Unique Device and User

In order for you to get the device unique ID and WL (Windows Live) Anonymous ID you need to first declare a couple of things in your WMAppManifest.xml file.  If you attempt to retrieve this information without these capabilities,  it will throw a UnauthorizedAccessException.  Remember, like all capabilities, the user will be alerted that you require this information before they download your application.  So use this only if you need it.

    <Capabilities>
      ...
      <Capability Name="ID_CAP_IDENTITY_DEVICE"/>
      <Capability Name="ID_CAP_IDENTITY_USER"/>
      ...
    </Capabilities>

Now you can access the the desired properties.  First add a using statement

 

using Microsoft.Phone.info;

 

Then access the properties.

 

public static byte[] GetDeviceUniqueID()  
        {  
            byte[] result = null;  
            object uniqueId;  
            if (DeviceExtendedProperties.TryGetValue("DeviceUniqueId", out uniqueId))  
                result = (byte[])uniqueId;  
  
            return result;  
        }  

public static string GetWindowsLiveAnonymousID()
        {
            string result = string.Empty;
            object anid;
            if (UserExtendedProperties.TryGetValue("ANID", out anid))
            {
                if (anid != null && anid.ToString().Length >= (ANIDLength + ANIDOffset))
                {
                    result = anid.ToString().Substring(ANIDOffset, ANIDLength);
                }
            }

            return result;
        }

Window Phone Web Marketplace

imageWith the release of Mango, Microsoft has also release a new Web (read online non zune) version of the Marketplace.  This is a great place to discover all of the applications that are available for your Windows Phone.

In addition to allowing you to search for applications, it also lets you install the applications OTA (Over the Air).  This makes it really easy to explore and download applications.  Lets walk through the steps necessary to download apps from the new Web Marketplace.

 

  1. Navigate to http://www.windowsphone.com
  2. Click on the MarketPlace tab.
  3. Search for the application you would like to install. I am going to try 3D Paperball.  You can check out the screenshots and information on the application(including reviews)

    imageimage

  4. Click on the “Get free app” button (if it is a paid/trial app, you will see a Buy button)

    image

  5. Select the Phone you would like to send it to and hit Next
  6. If this is the first time that you are using the Web Marketplace, it will ask you to verify your phone number.  Do this and click next

    imageimage

  7. Click on the Get App link (If it is a paid app… it will confirm billing)
  8. Wait for it to be processed

    image

  9. Your app will then begin installing on your phone

    image

  10. That’s it….  Now go check out the marketplace.

Getting WP7 Device Info

As you are writing your WP7 applications you may come across the need to get information about the device your application is running on like the Firmware version, Manufacturer or the Memory the phone has loaded.  You can find all of this information in Microsoft.Phone.Info.DeviceStatus.

 

 1:  PowerSource =  Microsoft.Phone.Info.DeviceStatus.PowerSource.ToString();
 2: 
 3:  FirmwareVersion = Microsoft.Phone.Info.DeviceStatus.DeviceFirmwareVersion;
 4: 
 5:  HardwareVersion =  Microsoft.Phone.Info.DeviceStatus.DeviceHardwareVersion;
 6: 
 7:  Manufacturer =  Microsoft.Phone.Info.DeviceStatus.DeviceManufacturer;
 8: 
 9:  Name = Microsoft.Phone.Info.DeviceStatus.DeviceName;
 10: 
 11:   TotalMemory = (Microsoft.Phone.Info.DeviceStatus.DeviceTotalMemory / 

           1048576).ToString() + "MB";
 12: 
 13:  HasKeyboard = Microsoft.Phone.Info.DeviceStatus.IsKeyboardPresent;

 

 

Use this class to find the information you are looking for.  Hope that helps.

Windows Phone Camps

imageWindows Phone Camps

Fun, free and for all http://bit.ly/phonecamps






Register for Costa Mesa Phone Camp 10/13 (Sold Out)

Register for LA (Santa Monica) Phone Camp 11/10 (Sold Out)

Register for Nor Cal Phone Camp 10/20 (Meet @BrandonWatson)

Hit the ground running with the new Windows Phone 7.5 (codename “Mango”) at interactive Windows Phone Camps. These free, hands-on events are perfect for students and seasoned developers alike. In one jam-packed day, we’ll cover everything you need to design and publish a Windows Phone application, whether you build for Windows Phone, Android, Symbian, Web OS, or iPhone. We’ll also discuss how to earn money from your apps and share the latest innovations and inside tricks. Windows Phone experts will also be on hand to answer your questions and offer guidance, so register today – and get ready to start coding.

Agenda

8:00 AM

Arrival & Registration

9:00 AM

Windows Phone 7.5 Overview for Developers

9:45 AM

Building Windows Phone 7.5 Applications with Visual Studio

10:45 AM

Break

11:00 AM

Building Windows Phone 7.5 Applications with Silverlight

12:00 PM

Lunch

12:45 PM

Windows Phone 7.5 Fast Application Switching, Tombstoning,
and Multitasking

1:45 PM

Break

2:00 PM

Live Tiles and Push Notifications

3:00 PM

Monetizing a Windows Phone 7.5 Application

3:30 PM

Build Your App or Work on a Hands-On Lab

5:00 PM

Be What’s Next > Event Closing & Raffle

Prerequisites
Bring a notebook computer and identification. Also check out the APP HUB where you can get developer tools, learn about application features, understand common task for Apps and register and load your APP.

Your chance to win*
Don’t miss a chance to win your very own Windows Phone (ARV $500) – plus many other cool prizes. No purchase necessary, but you must be present to win.

Find a location near you and register here  http://bit.ly/phonecamps

Update Your Developer Mango Phones

NEW YORK - OCTOBER 11:  A person holds a new  ...

Image by Getty Images via @daylife

If you were one of the umpteen developers that upgraded your phone to the developers preview of Windows Phone code named Mango.  You remember the most used sentence in the instructions : “Back Up Your Phone”.  It was stated that in order to update your phone to the RTM version, you would need to restore this update FIRST and then update to RTM.

 

 

Well, I have good news for you. You can now update your phone from the Developer Preview DIRECTLY to RTM.  (But don’t delete that back up, just in case)

 

You can read all of the instructions below. (Borrowed from this forum post by Cliff Simpkins  http://forums.create.msdn.com/forums/t/92311.aspx  Winking smile  )

 

This update is being made available to those running build 7712 on a retail device that was updated to ‘Mango’ using the provisioning tool we published to Connect a couple months ago.

To receive the update, connect your retail device to your faithful Zune client. The path to RTM will be applied in two parts:

    • First, your device will receive the update that takes your phone from build 7712 to 7720
    • Next, the update will clean-up the pre-production provisioning and repoint your device to the production update servers

Once provisioned back to the production servers, your device is then ready and capable to receive updates specific to your device/carrier combination, making it possible for you to receive such updates as drivers and firmware. If your device had drivers made available over the summer, you should see them immediately; and in the coming weeks, you should see the Windows Phone 7.5 device updates from your carrier as they are available for your device. Check out the ‘Where’s My Phone Update?’ page for the latest global status info.

This is great news!

At this point, you’re back in a happy place and able to be supported once more by your carrier. And even better, thanks to some extra work by our engineering teams, this means that most of you will not need to restore back to 739x, and that your data and settings will remain intact – meaning no saved games.

There are a few caveats to this process that it is worth noting:

    • Download Zune 4.8: For best results, you should be running version 4.8.2345.0 of the Zune client. To update your Zune client, click on ‘Settings’ -> ‘Software’ -> ‘General’, and click the ‘Check for Updates’ button.
    • Support scoped to 7712: This de-provisioning process has only been tested on devices updated (a) using the provided provisioning tool and (b) running the pre-release build (7712) released via the pre-release servers. Folks still running on build 7661 should be provided the 7712 update as part of this update process. All other pre-release configurations are untested and unsupported.
    • Phone Backup and Disk Space: The first step of the update to 7720 is for Zune to perform another backup of your phone. As such, make a copy of your 7390 backup before you start on the update process (you may still yet need it) and be sure you have enough free disk space on your computer to support the backup.
    • Driver updates may trail: The dev de-provisioning process occurs separately from the Windows Phone 7.5 update process for the general customer base on the production servers. Once provisioned back to the production servers, you may still have to wait to be eligible for your device-specific updates. As such, you may still experience some quirks with your device until you receive device and carrier-specific updates tuned for your specific device. We will try to provide additional data here to allow you to know when you’re retail device is finally ‘done’, but I don’t have that information to share at this point.
But wait! Protect that backup!

Lastly, in the known issues category, it has been observed that a small number of users may not receive device-specific updates released in the July timeframe. As such, you should absolutely be sure to hold onto that copy of your 739x backup before you begin the update process and continue to keep it in a safe place.

Windows Phone updates are cumulative in nature, and assume the presence of those that came before them. As such, getting a later update without the earlier one can put you in a less than ideal place. For folks who fail to receive a prior update, they may need to resort to using the 7390 backup in order to receive these updates. While there will be a few folks that this won’t help move forward to a supported state, it’s best to be prepared in case it happens to you.

Enhanced by Zemanta