October 25, 2011  

 

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

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)

October 18, 2011  

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 “semi” 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.

October 13, 2011  

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.
October 10, 2011  

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.

October 5, 2011  

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.

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;
        }
|Categories :   Comments [6] Trackback
October 4, 2011  

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.

|Categories :   Comments [5] Trackback