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
Related
I work on .NetFramework WPF app and I need to run some UWP app, like calculator having only APPID (or family package name, I suppose) like:
Microsoft.WindowsCalculator_8wekyb3d8bbwe!App
Honestly I have no idea how to do it. Google doesn't help.
Process.Start() will not manage, as I don't have exe filepath.
Any suggestions?
I tried to reference UWP launcher but it failed.
Launching UWP application in simple C# app (WPF/Console)
WindowsCalculator is open source, you could get app's protocol name here. So you could use Launcher to launch WindowsCalculator app from WPF or Console.
private async void Button_Click(object sender, RoutedEventArgs e)
{
var res = await Launcher.LaunchUriAsync(new Uri("ms-calculator:"));
}
And this is sample. Please note, you need add Windows.winmd and System.Runtime.WindowsRuntime.dll for the WPF app. For more please refer this reply.
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.
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 am developing an WP8 app that uses a webbrowser control that shows statefull server content. On WP8 you can switch between apps manually. E.g. if you want to copy&paste some information from one app into a browser input field. If you switch that way, the current app instance stays alive. That means the web session and the current page of the browser control will stay available.
Now I want another app to send some data directly into the app with the browser control - without restarting it...
From what I know, there are three ways to handle inter app communication:
register a file type that will open the app by launching that file from local storage
register an app protocol and use Launcher.LaunchUriAsync() to submit parameters in a query string
use a shared storage file
Detailed information can be found here.
I think the last approach is not usefull, because after you have started the second app, there is now way to activate the calling app or is there any usefull way to reactivate the webbrowser app?
I tried the second approach, but I am running in an issue, because it starts a new instance by design. That means InitializePhoneApplication is called. There is the entry point for the custom UriMapper that reads the incoming parameters. So the old app instance is killed and all session data, cookies and input fields are gone. With WP webbrowser control you are not able to store the cookie and page state, so a fast app resume is not possible also.
private void InitializePhoneApplication()
{
if (this.phoneApplicationInitialized)
{
return;
}
RootFrame = new TransitionFrame();
RootFrame.Navigated += this.CompleteInitializePhoneApplication;
RootFrame.UriMapper = new AssociationUriMapper();
//...
this.phoneApplicationInitialized = true;
}
Is there any other way or a possibility to use the shown approaches to send data between apps without restarting them using LanchUri()?
That means, to send some data back to a running instance without reinitializing the whole app, so that the page state and session state are still available on the target app.
Best regards
Holger
FastAppResume is the solution. I haven't used it and thought it also reinitiates the app. But it doesnt. This example shows how to reuse the existing instance.
Regards
Holger
So I made a simple Windows Phone 8 app that uploads a text file to the user's SkyDrive account. My code works fine while my app is running in the foreground, but when I attempt to upload a text file when my app is closing , it doesn't seem to work.
I'm using the Live Connect SDK v5.3 for WP8.
SDK link: http://msdn.microsoft.com/en-us/library/live/hh826550.aspx
I'm using this piece of code to do the background upload when my app closes (when the user hits "back button" on their phone:
protected override void OnBackKeyPress(CancelEventArgs e)
{
SaveSkyDriveData();
base.OnBackKeyPress(e);
}
public async Task SaveSkyDriveData()
{
var res = await client.BackgroundUploadAsync("me/skydrive", new Uri("/shared/transfers/MyData.txt", UriKind.RelativeOrAbsolute), OverwriteOption.Overwrite);
}
Any ideas why this code doesn't work when the app is closing? I've read through the SDK that says this should work even after the app has been dismissed. Here's the SDK link for uploading files in the background: http://msdn.microsoft.com/en-us/library/live/hh826531.aspx#uploading_files
Thanks!
You cannot upload files during the closing of the app in WP as you only have about 10 seconds to save state before it's shutdown
You might be able to do it during de-activation but it would be a push as the timescales are the same.
A better solution would be to have a background task (scheduled task) that runs and checks for files to upload and does so periodically.
Another alternative depending on your use case would be to use the parse SDK rather than upload to SkyDrive unless there is a specific reason the file needs to be hosted on SkyDrive
Hope this helps
To revive an ancient thread, is this because you aren't awaiting your async task?
protected override **async** void OnBackKeyPress(CancelEventArgs e)
{
**await** SaveSkyDriveData();
base.OnBackKeyPress(e);
}
the compiler should be warning you that nothing is awaiting the task...
so nothing downstream knows that there's work in progress? so any async work that started probably doesn't complete before the app closes.
if that's related, there are other answers about waiting synchronously as well, like using Task.Run(() => SaveSkyDriveData()).Wait(); to make the async thing be synchronous,