IT tutorials
 
Technology
 

Windows Phone 8 : Location APIs (part 1) - Location Permission

10/7/2013 8:35:22 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

1. The Clipboard API

Windows Phone supports a common clipboard much like Windows. Users can add items to the clipboard while working with TextBox controls, and the copied text will remain in the clipboard for other applications to use. You can also access the clipboard programmatically with the Clipboard class. The Clipboard class has three simple static methods: SetText, ContainsText, and GetText. You can set text to the clipboard programmatically by using the SetText method, like so:

Clipboard.SetText("Hello World");

You can test to see whether there is data in the clipboard by calling the ContainsText method as well:

if (Clipboard.ContainsText())
{
  // ...
}

The last method (GetText) exists on the Clipboard class but is not available to Windows Phone applications. Calling GetText will throw a security exception. This means your application cannot read the clipboard; it can only test to see whether it has text and then push text onto the clipboard. The reasoning behind this is to prevent accidental leaking of user data to unauthorized applications. For desktop Silverlight, user approval typically is required to access the clipboard, but currently the decision is to just disallow it instead of introducing another pop-up confirmation that needs to be explained to the user. This is a limitation of the phone SDK, and you will need to work around it if you need to copy text from the clipboard.

2. Location APIs

Your application can determine where in the world the phone is at any moment. This is the same technology your GPS device uses to determine how to give you driving directions. The phones are required to have Assisted Global Positioning System (A-GPS) hardware. This is different from simple GPS location technology as the “Assisted” part is very important. Typical GPS devices rely on being able to locate three orbiting satellites to triangulate your location. Sometimes these systems were hurt by the lag in “syncing” with the three satellites and often structures (such as buildings or bridges) made GPS unreliable. Assisted GPS improves this by using GPS to give you high-precision geolocation when possible but can also fall back to use other ways of determining your location, including cell-phone tower triangulation and the Wi-Fi Positioning System.

Location Permission

To create a location-aware application, you will use the A-GPS on the phone. Because using location without the user’s consent would likely be a violation of privacy, your application has to specify that it can use the location APIs in the SDK. To do this, you need to add a new capability via the WMAppManifest.xml file. If you open the manifest in the editor, you can check off the location capability in the Capabilities tab, as shown in Figure 1.

Image

FIGURE 1 Requesting the location capability

When your application is installed, the Marketplace specifically asks the user whether he wants to allow your application to gather location information. Before your application can use location information, it must use the GeoLocationWatcher class (in the System.Device.Location namespace) to check whether the user has granted permission:

// using System.Device.Location;
// Create the Watcher (and clean it up when done)
using (var watcher = new GeoCoordinateWatcher())
{
  if (watcher.Permission == GeoPositionPermission.Granted)
  {
    // Find the location
  }
}

The Permission property of the GeoCoordinateWatcher class will tell your application whether it is allowed to use location information. If permission is denied and you attempt to use location information, the class will throw an exception. In addition to checking for permission, you must allow the user to disable this capability in your application.

 
Others
 
- SQL Server 2008 : Data compression (part 2) - Data compression considerations
- SQL Server 2008 : Data compression (part 1) - Row compression, Page compression
- SQL Server 2008 : BLOB storage with FileStream (part 2) - FileStream data
- SQL Server 2008 : BLOB storage with FileStream (part 1) - BLOBS in the database, BLOBS in the file system
- Windows Small Business Server 2011 : Managing Software Updates - Using SBS Software Updates (part 2) - Deploying Updates
- Windows Small Business Server 2011 : Managing Software Updates - Using SBS Software Updates (part 1) - Configuring Software Update Settings
- Windows Small Business Server 2011 : Managing Software Updates - The Patching Cycle
- Windows Phone 7 : Creating a Game Framework - Benchmarking and Performance (part 2)
- Windows Phone 7 : Creating a Game Framework - Benchmarking and Performance (part 1)
- Operating and Monitoring Exchange Server 2013 : Monitoring Enhancements in Exchange 2013
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us