Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# uwp launch apps

With this code below:

await Windows.System.Launcher.LaunchUriAsync(new Uri(@"ms-windows-store://review/?ProductId=9wzdncrfj2wl"));

I am opening Facebook app in Microsoft Store. There is a Launch button on that page. With it user runs the application.

How can I run the application with it's product ID?

I managed to open app with this code:

await Windows.System.Launcher.LaunchUriAsync(new Uri("fb:post?text=foo"));

But I want to open it with ID.

I have found this code, but it is not working:

await Windows.System.Launcher.LaunchUriAsync(new Uri(@"ms-windows-store://pdp/?ProductId=9wzdncrfj2wl"));

How to open installed app with ID? Or, if there is another way to check if App is installed, if it is then launch it, if it is not then show it in store, so user can install it manually. The app I am developing is Windows 10 UWP...

I have a situation where there is no URI for application, so I have to open it via it's ProductID or ProductFamily...

So, this is the shortcut's target that is opening that app: C:\Windows\explorer.exe shell:AppsFolder\A88BB54F.N1info_gvc78jvcn5cg0!App

Is there any chance I can use this in UWP app to launch app?

Does anyone got the link from LAUNCH button in Windows Store? So, I would put that in URI, just like link from GET button:

ms-windows-store:PDP?PFN=A88BB54F.N1info_gvc78jvcn5cg0&referrer=unistoreweb&webig=39694073-f9af-436f-a82b-abb9d9f644f0&muid=097C7AA3CA2C6EE22D237359CE2C689A&websession=c9916902dd014ec2b5a9e0390a28c26d

I am using it like this:

await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-windows-store:PDP?PFN=A88BB54F.N1info_gvc78jvcn5cg0&referrer=unistoreweb&webig=39694073-f9af-436f-a82b-abb9d9f644f0&muid=097C7AA3CA2C6EE22D237359CE2C689A&websession=c9916902dd014ec2b5a9e0390a28c26d"));

and it is showing app in store.

Thanx.

like image 529
user3239349 Avatar asked Feb 01 '17 11:02

user3239349


2 Answers

It is possible by using Package Manager:

using Windows.Management.Deployment;

var app = await GetAppByPackageFamilyNameAsync("Microsoft.WindowsCalculator_8wekyb3d8bbwe");

if(app != null)
{
  await app.LaunchAsync();
}    

static async Task<AppListEntry> GetAppByPackageFamilyNameAsync(string packageFamilyName)
{
    var pkgManager = new PackageManager();
    var pkg = pkgManager.FindPackagesForUser("", packageFamilyName).FirstOrDefault();

    if (pkg == null) return null;

    var apps = await pkg.GetAppListEntriesAsync();
    var firstApp = apps.FirstOrDefault();
    return firstApp;
}

And add one capability to the Package.appxmanifest :

<?xml version="1.0" encoding="utf-8"?>    
<Package xmlns:...
         xmlns:rescap = "http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" 
         IgnorableNamespaces="... rescap">
  ...
  <Capabilities>
    ...
    <rescap:Capability Name="packageQuery" />
  </Capabilities>
</Package>

Learn more about restricted capabilities: https://learn.microsoft.com/en-us/windows/uwp/packaging/app-capability-declarations#restricted-capabilities

like image 192
Yevhen Cherkes Avatar answered Oct 18 '22 04:10

Yevhen Cherkes


If you want to launch one app from another, the target app must have registered URI activation and handle that case. More about that you can read at MSDN.

Lots of apps in the store has registered URI scheme, there are some lists over the internet, like this one, however I'm not sure if it's actual and which apps work with UWP.

like image 1
Romasz Avatar answered Oct 18 '22 03:10

Romasz