Cortana App Open a Webpage - c#

I need to write an Cortana extension (app, experience, plugin, etc..) that will receive a query from the user and based on this query construct an webpage URL and open that URL in the default client browser. My question is, can an App do that? Could you share any code example? Can this app run both on cell phones and windows laptops/desktops?

I believe so. You can create an app that implements Windows.ApplicationModel.AppService IBackgroundTask cortana will activate your background service if you register a VCD file with the right 'ListenFor' commands. You wire your app via "VoiceCommandService Target=".
Your background app would then launch the default browser.
Here is a step by step guide.

Here is the code:
string uriToLaunch = #"http://www.bing.com/";
var uri = new Uri(uriToLaunch);
await Windows.System.Launcher.LaunchUriAsync(uri);

Related

open kaizala (iOS) app and start a chat with specific number via URI possible?

we’re developing a (iOS) phonebook app using Xamarin.
From our app we want to be able to start Kaizala (iOS) App and open a chat to a specific number, ideally using an URI schema like below:
Here is an example of how we did this for MS Teams (iOS) and WhatsApp (iOS):
// try open MSTeams and open a chat to user (CommandParameter)
await Launcher.TryOpenAsync(new Uri("https://teams.microsoft.com/l/chat/0/0?users=" + CommandParameter));
// try open WhatsApp and open a chat to user (CommandParameter)
await Launcher.OpenAsync(new Uri("whatsapp://send?phone=" + CommandParameter));
is that possible for kaizala as well? didn’t find an answer while searching through the docs.
Is there a similar URI schema for Kaizala App? Or an alternative way to achieve this?
Please advise, Thank a lot!

Using ASP.NET MVC, is it possible to execute a WPF .exe file after downloading it?

I have an ASP.NET MVC web application with a button to download an .exe file for an existing WPF application. It downloads fine, but when clicked in the browser window, it doesn't execute. How would I fix this?
[HttpGet]
public FileResult downloadFile()
{
var fileName = string.Format("MyApp.exe", DateTime.Today.Date.ToString("dd-MM-yyyy") + "_1");
var tempOutPutPath = Server.MapPath(Url.Content("~/File/")) + fileName;
byte[] finalResult = System.IO.File.ReadAllBytes(tempOutPutPath);
if (System.IO.File.Exists(tempOutPutPath))
System.IO.File.Delete(tempOutPutPath);
if (finalResult == null || !finalResult.Any())
throw new Exception(String.Format("No Files found"));
return File(finalResult, System.Net.Mime.MediaTypeNames.Application.Octet, Path.GetFileName(fileName));
}
This is a security issue, so i would say no. Imagine the disaster if links on malicous sites could download and run programs on the end users pc.
Don't know why you need it, but if you need to launch your wpf app from a browser. Then you could make a link to reference a uri scheme that points to your already installed application. You would have to add it to registry during an install routine or a one time job in your app.
Registering an Application to a URI Scheme in windows 10
Hope this helps
I think this is the closest you can get to run your application from a browser. But making it launch automatically after download is not possible.
like matcsr pointed out what you cannot force a user to execute a file in their download folder. But if what you want is to distribute your WPF app from the web then you need to setup a ClickOnce Web deployment. More info Here: Choose a ClickOnce deployment strategy

Wait for an launched application to stop

We are currently working on a project in UWP where we have to start an external application to modify some documents.
We looked into the Windows.System.Launcher API but it seems that we need more than what it can offer us.
As we launched the application from a file, we use the LaunchFileAsync method, based on the example given by the MSDN :
async void DefaultLaunch()
{
// Path to the file in the app package to launch
string imageFile = #"images\test.png";
var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile);
if (file != null)
{
// Launch the retrieved file
var success = await Windows.System.Launcher.LaunchFileAsync(file);
if (success)
{
// File launched
}
else
{
// File launch failed
}
}
else
{
// Could not find file
}
}
So far, the example suit us well but we also need to be warned when the user is done with the file. The best would be to be able to give the launcher a callback method.
We haven't found anything like that yet in the documentation. Is this even possible ? Do we need to use another solution ?
TL;DR : Is there a solution to open another application from a UWP app and wait for it to return a result object ?
If the external app is also a UWP app then Launcher.LaunchUriForResultsAsync is designed for this. It will launch the target app then wait for the app to call back with the results.
See Launch an app for results for a full walkthrough of how this works.
If the target app isn't a UWP app then you can implement the same thing yourself: both apps declare a protocol. The client launches the server with the server's protocol. When the server's done it notifies the caller by launching the client's protocol.
You might also want to look into App Services which allow a UWP server app to expose a REST-like service to clients on the local system. 
The app process isolation model means you can't do this from a UWP app. As you just want to know when an arbitrary program has finished you could write this in traditional .net/win32 and include that in your UWP app via the desktop bridge.

How can I open an image in the default photos app?

I have an app that captures images from the device's camera and saves them as StorageFiles to a folder in my app's roaming data. I've been trying to make a page that will open the image and show a preview, but I've been having many problems doing that, so I want to just open the image in the default photos app. However, I can't find any way to do that. Using await Launcher.LaunchUriAsync(new Uri(#"ms-appdata:///roaming/folder/img.jpg")); asks if I want to search for an app in the Store (searches for "ms-appdata"). Does the native Photos app for Windows (Phone) have a dedicated URI scheme? Also, I am targeting Windows 10 with this app, so the URI schemes (if any) may have changed.
Launcher.LaunchUriAsync is for launching an application using the URI scheme, this is not what you want.
Instead you'll want to launch an app based on a file:
Get the image as a StorageFile
var imageFile = await StorageFile.GetFileFromPathAsync(#"ms-appdata:///roaming/folder/img.jpg");
Then you tell the OS to launch an app to handle that file. It's then up to the user to choose which app to handle the image file:
var success = await Windows.System.Launcher.LaunchFileAsync(imageFile);
You can read more about "launching" files here.

open specific file in appropriate app from inside Windows 8 App

I'm creating Windows 8 app in which i need to list specific files in a page and then let user open that file. I'm using C# as backend.
I want to ask this (as in the image below), to my user when they try to open any app listed in my app page.
when user select specific app, then the file that is clicked should open in that app.
Unlike previous versions of Windows, the User is now in control of file associations.
To show the launch using the Window above, you can refer to the complete example of launching options here.
The core of it is deciding on a Point on the screen (which is openWithPosition in the example below) and then calling LaunchUriAsync with the options set to display the window.
var options = new Windows.System.LauncherOptions();
options.DisplayApplicationPicker = true;
options.UI.InvocationPoint = openWithPosition;
options.UI.PreferredPlacement = Windows.UI.Popups.Placement.Below;
// Launch the URI.
bool success = await Windows.System.Launcher.LaunchUriAsync(uri, options);
The linked example code contains a function that can compute a reasonable Point given a XAML element.

Categories

Resources