Opening app from app

BitSmithy 1,956 Reputation points
2024-06-08T20:16:31.6733333+00:00

Hello,

I want to open app from other app. Function should work in this way

If app is found as installed, open the app, but if app isnt found open it's page in Windows Store

I use such code:

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

Uri appUri = new Uri("myapp://");              
Uri appWinStoreUri = new Uri("https://www.microsoft.com/store/apps/xxxxxxxxx");             

var success = await Windows.System.Launcher.LaunchUriAsync(appUri);              

if (success)
             {                  
// URI launched
             }              
else              
{                 
// URI launch failed                 
await Windows.System.Launcher.LaunchUriAsync(appWinStoreUri);             }          

}

when I use this code and app isnt found as installed, dialog opens and allows to search the app in Windows Store. The returned value is allways success.

How to code functionality which I want

Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. Roy Li - MSFT 32,721 Reputation points Microsoft Vendor
    2024-06-10T05:05:53.47+00:00

    Hello,

    Welcome to Microsoft Q&A!

    The returned value is always success.

    This behavior is expected. The value indicates whether this method is running without error. When it returns success, there might be two different scenarios.

    1. The target app is installed, and it will be launched.
    2. The target app is not installed, and you will be guide to the Microsoft Store.

    Both of the scenario means the LaunchUriAsync method works correctly. Only if there are something wrong inside the LaunchUriAsync method or the Launcher object itself, the return value sill be failed.

    Back to your question, you want to navigate to the Microsoft Store if the target app is not installed. As I've mentioned above, UWP has already implemented this in the LaunchUriAsync method. Please check the LauncherOptions.FallbackUri Property. It's a value that represents a URI that the user should be taken to in the browser if no app exists to handle the file type or URI.

    Please use the following code:

    Uri appUri = new Uri("Testuri-alsdk:");
    Uri appWinStoreUri = new Uri("https://www.microsoft.com/store/apps/xxxxx");
    LauncherOptions options = new LauncherOptions();
    options.FallbackUri = appWinStoreUri;
    var success = await Windows.System.Launcher.LaunchUriAsync(appUri, options);
    

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful