Advertisements

Archive

Archive for the ‘Windows Phone’ Category

Get nearby locations using Bing maps – WP 8

March 20, 2014 2 comments

Using ‘Bing Maps Task’ we can get the nearby locations (i.e., Hospitals,Coffee shops or Shopping malls) on the Map.

Add a button to your XAML page and on ‘Click’ event handler place below code.

UI XAML

UI XAML

using Windows.Devices.Geolocation;

private async void btnMapTask_Click(object sender, RoutedEventArgs e)        {

// Get the Current location Coordinates

Geolocator geolocator = new Geolocator();

geolocator.DesiredAccuracyInMeters = 50;

Geoposition position = await geolocator.GetGeopositionAsync(

maximumAge: TimeSpan.FromMinutes(1), timeout: TimeSpan.FromSeconds(30));

// Initialize BingMapsTask

BingMapsTask bingMapsTask = new BingMapsTask();

// Pass the current location coordinates

bingMapsTask.Center = new GeoCoordinate(position.Coordinate.Latitude, position.Coordinate.Longitude);

bingMapsTask.ZoomLevel = 2;

// Search Term; To search coffee shops set ‘coffee’

bingMapsTask.SearchTerm = “hospital“;

bingMapsTask.Show();

}

When you click on the button, we will get below screen.

 

Allow load Map

Allow load Map

Once you click on ‘allow’ , we will get a bing map with nearest hospitals.

Nearest Hospitals

Nearest Hospitals

Also we need to enable following two Capabilities in application manifest file “WMAppManifest.xml”

1.ID_CAP_LOCATION
2.ID_CAP_MAP

🙂

Advertisements
Categories: Windows Phone Tags: , ,

A first chance exception of type ‘System.Windows.Markup.XamlParseException’ – WP8

Other day I got below error while executing my application.

A first chance exception of type ‘System.Windows.Markup.XamlParseException’ occurred in System.Windows.ni.dll

The exception was in ‘App.xaml.cs’ file’s InitializeComponent() method

XamlParseException

XamlParseException

Reason

  • There could be many reasons for the exception
  • Even if there is an invalid space in your xaml file it throws the exception

Fix

  • To get the exact reason for the issue, add the exception in your ‘Debug’
    • Debug->Exceptions
    • Press Add and type in, “System.Windows.Markup.XamlParseException” and select Common Language Runtime Exceptions
Add Exception

Add Exception

    • Run the application
    • It will pinpoint the exact reason for the exception
  • In my case I had an empty space in my xaml file

🙂

Text to Speech – WP8

Windows Phone 8 has included the Text to Speech feature out of the box in the platform.Text to speech is very easy to use in your App (only takes 2 lines of code) using ‘SpeechSynthesizer’ class.

Text to Speech

Text to Speech

Below is the code

            var synthesizer = new SpeechSynthesizer();

await synthesizer.SpeakTextAsync(“Your text here”);

Copy and paste above code in button ‘Click’ event.

Also we can set the ‘VoiceInformation’ (i.e., Language, Gender etc…) to the speech.

Refer link for more details.

🙂

Playing a song from library – WP8

Here is the logic to play a particular song from library.

Logic is to loop through all the songs in Media Library and if the song name matches to our song play the song.

string favoriteSong = “mySong.mp3”;

using (Microsoft.Xna.Framework.Media.MediaLibrary library = new Microsoft.Xna.Framework.Media.MediaLibrary())            {

foreach (var song in library.Songs)                {

if (song.Name == favoriteSong) {

FrameworkDispatcher.Update();

// Play the song

Microsoft.Xna.Framework.Media.MediaPlayer.Play(song);

break;

}

}

library.Dispose();

}

🙂

Setting the Start Page – Windows Phone 8

In my windows phone 8 application I have 2 xaml files.

By default when you run the application, it opens ‘MainPage.xaml’.

To set my second file (i.e., ‘MediaPlayer.xaml’) as start page.

• Open ‘WMAppManifest.xml’
• In ‘Application UI’ tab, set Navigation Page = MediaPlayer.xaml

Set Navigation Page WP8

Set Navigation Page WP8

We can also change it in App.xaml in the Application_Launching event with below statement

App.RootFrame.Navigate(new Uri("/MediaPlayer.xaml",UriKind.Relative));

🙂

System.UnauthorizedAccessException – Windows Phone 8 application

These days I started practicing windows phone 8 applications.
In my first application, I tried to call a number using Windows Phone Stack using below code.

WP 8 Phone DIaler

WP 8 Phone DIaler

PhoneCallTask phoneCallTask = new PhoneCallTask();

phoneCallTask.PhoneNumber = “1234567890”;

phoneCallTask.DisplayName = “Rajeev”;

phoneCallTask.Show();

While executing the code block I got below exception

An unhandled exception of type ‘System.UnauthorizedAccessException’ occurred in System.Windows.ni.dll

Access Denied WP8

Access Denied WP8

Fix

  • We have to enable ‘Phone Dialer’ capability in ‘WMAppManifest.xml’ file
  • In the Project ,open ‘WMAppManifest.xml’ file under ‘Properties’ folder
  • Go to ‘Capabilities’ tab and check ‘ID_CAP_PHONEDIALER’ check box.
WMAppManifest

WMAppManifest

App Manifest file

  • Each Windows Phone app has a manifest file that contains details about the app, such as the App ID and the capabilities that the app uses.