The UWP app I'm working on uses Launcher to launch another UWP app that I also wrote. Here's the code I'm using to launch the other app:
var uriToLaunch = "testapp-mainpage://";
var uri = new Uri(uriToLaunch);
bool success = await Windows.System.Launcher.LaunchUriAsync(uri);
So far, this code is able to launch the other app I wrote, but it just opens up the app window with the default blue background with an X in the middle, basically the default UWP splash screen. I've tried setting the URI to target the MainPage of the app, but no matter how I try to modify the URI, it just launches to the default splashscreen. The app I'm launching is just a very basic, default UWP app at the moment. What am I missing or doing wrong that it the app being launched doesn't fully initialize?
You need to modify the launched app to handle protocol activation. The default wizards generate an app.xaml.cs which handles typical activation via OnLaunched but not alternate activations via OnActivated:
protected override void OnActivated(IActivatedEventArgs args)
{
if (args.Kind == ActivationKind.Protocol)
{
ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
// TODO: Handle URI activation
// The received URI is eventArgs.Uri.AbsoluteUri
// You'll likely want to navigate to a page based on AbsoluteUri
// If you just want to launch the main page you can call essentially
// the same code as OnLaunched
}
}
See Handle URI activation on MSDN for more details. See the Association Launching Sample for a concrete example.
Related
I have a Xamarin Forms App for android with LaunchMode = SingleTop in MainActivity.cs. When the app in invoked for the first time via Deep linking URL, the method OnAppLinkRequestReceived is executed in App.XAML.cs file.
In this method I'm setting some app parameters received from URL.
Once I open the app and push it to background using Home button and call the URL again, the app which is running in the background is made active, but the method OnAppLinkRequestReceived is not executed at all. So, I was not able to change the app parameters.
When I kill the app and open the URL again, a new instance of the app is created and OnAppLinkRequestReceived is executed.
Is there any way to invoke OnAppLinkRequestReceived each time the app URL is called, irrespective of whether the app is already running or not ?
The method OnNewIntent in MainActivity.cs is blank earlier. I added a call to the base method.
Now, when I try to reopen the app from background, the method OnAppLinkRequestReceived is executed.
protected override void OnNewIntent(Intent intent)
{
// Added this line
base.OnNewIntent(intent);
}
I have created a BackgroundTask to run a WebService, however if i run my solution with debugger attached, everything works fine, slowly, but fine. But when i hit start in the appmanager (webinterface) it always says "failed to start package [MYPACKAGEID]". So what am i missing?
Here is the complete project: https://github.com/naice/HomeAutomation.git
public sealed class StartupTask : IBackgroundTask
{
internal static BackgroundTaskDeferral Deferral = null;
public async void Run(IBackgroundTaskInstance taskInstance)
{
//
// TODO: Insert code to perform background work
//
// If you start any asynchronous methods here, prevent the task
// from closing prematurely by using BackgroundTaskDeferral as
// described in http://aka.ms/backgroundtaskdeferral
//
Deferral = taskInstance.GetDeferral();
await ThreadPool.RunAsync(async workItem => {
RestWebServer restWebServer = new RestWebServer(80);
try
{
// initialize webserver
restWebServer.RegisterController<Controller.Home.Home>();
restWebServer.RegisterController<Controller.PhilipsHUE.Main>();
await restWebServer.StartServerAsync();
}
catch (Exception ex)
{
Log.e(ex);
restWebServer.StopServer();
Deferral.Complete();
}
}, WorkItemPriority.High);
}
}
The point is that there is no problem with the code or even the manifest, it seems that it's just not meant to run while the device is in "headed" mode, you need to set it as a satrtup headless app and then restart the device.
Edit: All these problems are gone with the latest version 10.0.14279.1000 and now the GUI finally works as it should.
I have been struggling with this to and have had great success with this method that might help someone. All is done in Power Shell
Put the device into headless mode, in some way I donĀ“t think this is mandatory but I have not succeeded without it.
Edit: This is not the case any more, it works as it should now.
https://ms-iot.github.io/content/en-US/win10/HeadlessMode.htm
Start the app in headless mode and add it to the startup app list
To see what apps are in the startup list type
IotStartup startup
To add a headless app type in command
IotStartup add headless [Task1]
To add a headless app type in command
IotStartup startup headless [Task1]
To find the app name you can use the command
IotStartup list
To see that your app are in startup list type
IotStartup startup
Then reboot your device!
I have also had some problems related to removing apps from startup and then try to debug them via Visual Studio and in some cases the only solution were to flash the SD card with a new image.
For a complete list of available commands
https://ms-iot.github.io/content/en-US/win10/tools/CommandLineUtils.htm
I am working on a project in which i have to integrate other apps/games with my platform. Through which i can run them. So their is one bad test solution is that i make them hardcodedly integrate them inside my framework as a part of framework. But that is crap.
So, my question is can i run other installed apps(these apps will be downloaded from store separately) through some code from my platform and I know data can be transfer from one app to other apps.
It should be like when i click on Play App Button then an installed app will get start and i transfer some settings to it and when user finish playing that app some data get transfer back to my platform and my platform resumes to corresponding state.
For opening other app form your app you have to know the uri for the app for example You want to open "another app"
string anotherappURI = "anotherapp_uri_value:///?anyVariable=value";
Uri uri = new Uri(anotherappURI);
await Launcher.LaunchUriAsync(uri);
And if you want to make a uri for your app so that it can be open from another app please follow the steps
Double click on package.appxmanifest file in the project
In the Declaration tab, select "Protocol" in the drop-down list and click on add
Enter "your_app_URI_displayname" as Display Name and "your_app_URI" as the Name
Save these changes
Now after activation (when your app is called and opened) how get the activation
Go to App.xaml.cs file
Override the OnActivated method
Insert this piece of code within :
Code:
protected override void OnActivated(IActivatedEventArgs args)
{
if (args.Kind == ActivationKind.Protocol)
{
ProtocolActivatedEventArgs eventArgs = args as
ProtocolActivatedEventArgs;
// TODO: Handle URI activation
// The received URI is eventArgs.Uri.AbsoluteUri
}
}
NOTE: Please upvote and accept it as answer if helpful
I'm trying call my application on OnShareTargetActivated() method by LaunchUriAsync() but it doesn't work.
I have a protocol called "myapp" in appmanifest. When I put "myapp://test" on File Explorer, my application is launched, but when I do it:
protected async override void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
{
Uri uri = new Uri("myapp://test");
await Windows.System.Launcher.LaunchUriAsync(uri);
}
This occurs when the user clicks on my application that is on Charm Bar in Share option. But the application is never launched.
sharing app sample (http://code.msdn.microsoft.com/windowsapps/Sharing-Content-Target-App-e2689782)
You should check the format , of what you are sharing , metro will only accept some type of content to share , Sharing format are Text,uri,Bitmap,storageitems,Html
share target code and pictures (http://blogs.msdn.com/b/going_metro/archive/2012/05/03/integrating-with-windows-8-share-charm-part-1-receiving-data.aspx)
if u find useful , pls acccept as answer
I have made one console application for email notification in c#.
Can i convert this console application in to window service?
Thanks.
In visual studio, create a "Windows Service" project instead of a "Console Application". Look in the code that gets generated for you. There will be an OnStart() and OnStop() method. Those are the methods that will be called when your service is started and stopped. Put your code in those methods and you will have a Windows Service.
Contrary to some of the suggestions made by other answers, you probably can't do what you want using a Windows Service. It can't display the "notification" you expect because services can't display any kind of user interface.
The appropriate solution is to create a regular application that runs in the background without showing any windows. You can't do this with a console application (well, you can, but let's not overcomplicate things) because each time you run it, the console window will be displayed. But if you create a standard Windows application (either a Windows Forms or WPF application) then just don't create a window, everything will work out just fine.
You'll probably want to create and place an icon into the taskbar's notification area, which will handle displaying the notification upon the arrival of email. If you're creating a WinForms application, this can be done easily by using the NotifyIcon component.
Something like (warning, written without the aid of a compiler!):
static class Program
{
[STAThread]
static void Main()
{
// Standard infrastructure code
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Create a context menu and add item(s) to it
ContextMenu mnu = new ContextMenu();
MenuItem mnuExit = new MenuItem("E&xit");
mnu.MenuItems.Add(mnuExit);
mnuExit.Click += mnuExit_Click);
// Create the NotifyIcon
NotifyIcon ni = new NotifyIcon();
ni.Icon = new Icon(GetType(), "icon.ico");
ni.Text = "Email Notifier";
ni.ContextMenu = mnu;
ni.Visible = true;
// Run the application
Application.Run();
// Before exiting, remove the NotifyIcon from the taskbar
ni.Visible = false;
}
private static void mnuExit_Click(object Sender, EventArgs e)
{
Application.Exit();
}
}
When I go about this, I write the application in a class that does not consider its self a console application. By that I mean I dont write to the Console. I use log4net to write everything to... just log to Info. Use the console app to call the application class and in the app.config you can have an appender for console logging... so you get the console output. In the windows service this will just write to a file or not at all for the Info level logging. Its important to note the differences between a console app and a service... a service is not interactive and you can not input anything, so you app must consider this. For the windows service use the same class, but use the windows service project to start it.
ApplicationLogic: Has all the logic to run the application. Can take the arguments to make the app run the way it needs to, but does not interact with the console (can, but it would be bad design). Writes everything to logging (log4net maybe).
ConsoleApp: Is a wrapper around ApplicationLogic that can prompt the user for what ever it needs, can prompt for input and send it to ApplicationLogic. Has a log4net console appender if you need to see the output from ApplicationLogic.
WindowsService: Is a wrapper around ApplicationLogic. Has predetermined logic to keep it looping and running the Application logic. Logs to a file, no console output.