PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 12, 2022

[FIXED] How can I natively launch an external app from within Xamarin.Forms?

 September 12, 2022     c#, cross-platform, xamarin, xamarin.forms     No comments   

Issue

As the question title suggests, I'm looking for a way to launch an external app from within a Xamarin.Forms app. For example, my app has a list of addresses, and when the user taps on one of them, the built-in map app for the current platform would open (Google Maps for Android, Apple Maps for iOS). In case it matters, I am only targeting Android and iOS.

I could use a dependency service and write the app-launching code on a per-platform basis, of course, but I'd prefer if I only had to write it once. Is there a native way to do this in Xamarin.Forms? I was unable to find anything that officially documented this on the Xamarin site or forums.


Solution

Use Device.OpenUri and pass it the appropriate URI, combined with Device.OnPlatform to format the URI per platform

string url; 

Device.OnPlatform(iOS: () =>
  {
     url = String.Format("http://maps.apple.com/maps?q={0}", address);
  },
  Android: () =>
  {
    url = String.Format("http://maps.google.com/maps?q={0}", address);
  });

Device.OpenUri(url);


Answered By - Jason
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing