I am developing an app based on a mobile website which runs inside a Windows Runtime WebView for Windows Phone 8.1. Currently, I am looking for a way to catch link clicks in the app's webview which start with a certain pattern. In the Windows Phone Silverlight version, the following was possible:
In my webview I display links like this
Do something in the app
Do something different in the app
In the app, I catch a click on such a link with the following code
MyWebView.Navigating += HandleOwnStuff;
void HandleOwnStuff(object sender, NavigatingEventArgs e) {
String url = e.Uri.ToString();
if(url.StartsWith("ownstuff:")) {
// check which function has been called and do something in the app, e.g. open the camera
}
}
Unfortunately, this approach is not possible in a WinRT app any more. Whenever I click such a link, the launcher opens with the message "Search for an app in the store".
The "NavigationCompleted" handler of the WebView is not called - this link click is catched before any handler of the WebView is called.
An approach which would work is using the UnsupportedUriSchemeIdentified handler, which - unfortunately - is only available starting from Windows 10 in UWP.
Another solution would be to completely rewrite my website so that the ScriptNotify handler can be invoked - which would be way too much work, since the website now also runs in normal browsers, Android and iOS devices - so this approach is definitely not worth the trouble.
Does anyone know a solution? Thanks.
I have talked about this with MSFT for awhile. Your right, with win10 that's why that event was added. The best way to workaround it is to change the website.
Related
At the moment I am creating an app to simulate simple mechanical motion in UWP. Instead of creating them all in one blank app I have created multiple different apps for the different types of simulation, eg: single particle, connected particles, pulleys etc... I was wondering if there was a way in which I could have a menu and then when a specific button is clicked the app associated with that button is opened, for example:
private void OpenSingleParticle_Click(object sender, RoutedEventArgs e)
{
//open single particle app
}
Thanks for any help that you can offer
Matt
You need to register app to handle custom URI, then you can call this app using launch app from uri. Take a look at msdn articles:
https://learn.microsoft.com/en-us/windows/uwp/launch-resume/handle-uri-activation
https://learn.microsoft.com/en-us/windows/uwp/launch-resume/launch-app-with-uri
Moreover you can even launch other apps for result as it's possible in Android.
I have a Windows store app I want to run (if not running) or expand (if not expanded) of another of my app written in WPF.
Through The Process.Start() I could not do. Tell me, can this be done? Thanks for the help!
To launch an UWP app from another app, you could make use of deep linking.
Here is a great article describing exactly how to do that
In summary, you need to add a protocol declaration (essentially a URL with a custom scheme), handle the activation event and then you can launch that app by navigating to that URL from your other application.
I am developing 2 apps in WP 8.1.
One should send requests(I call it "sender") and the other one should answer on them (I call it "receiver"). Both will be installed on the same WP device.
The perfect solution will be the one that user will not see in the UI that some "communication" is happening with different application.
But no matter how I try, the turnstile animation is displayed whenever "sender" hide/get visible.
[I removed splash screen, set transitions to null. However even if I close the receiver immediately (after the LaunchUri was called) I still can see the turnstile animation]
Imagine this example:
"sender":
User will click on "test button" and this code will be called:
await Launcher.LaunchUriAsync(new Uri("myreceiver:giveMeYourSecret"));
in "receiver"
as the answer on this code:
await Launcher.LaunchUriAsync(new Uri("mysender:MySecretPassword"));
and closes itself.
in "sender":
MySecretPassword is displayed in some TextBlock.
I know that this example is nonsense. I just need to achieve communication between 2 apps without any "not-wanted animations"(like turnstile).
My Questions:
Is there another way how to communicate between 2 windows phone 8.1 apps than via LaunchUri?
Is it possible to remove turnstile animation when the app is being resumed/deactivated ?
Thanks for any suggestions :)
In my Universal app, (Windows 8.1 Windows Phone8.1), I want to know the reason why my app is suspended like due to a launch of a launcher(Mail, File picker etc) or user pressed the Windows button. Is there a way to determine this?
Unfortunately you can't know what caused the app's suspension. Unlike the LaunchActivatedEventArgs in the OnLaunched method for example, that contain the Kind property the SuspendingEventArgs in the OnSuspending method don't provide any such information.
However, there are only so many reasons that an app can be suspended. Like you said (in windows phone only) it can be suspended due to a launch of a launcher or a protocol and by the windows button.
The windows button is the only suspension way of which you have no control. For all the others you can trick the system and for example set a static global variable that you update when you launch an operation that would suspend your app and check it in OnSuspending
In WP7 and WP8 I just needed to clear the backstack in a page, then press Back button and the app is closed. In WP8.1 I do Frame.BackStack.Clear(), press Back and the app just minimizes.. How to kill it with Back button?
You can add, in your main page definition:
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
Then
private void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
if (!e.Handled && Frame.CurrentSourcePageType.FullName == "YourApp.MainPage")
Application.Current.Exit();
}
Warning: As others said, you should not use this and let the system handle the app closure. For example, if you use the Application Insights, I found that they are not sent to Azure when in Release mode
I think the above has been depreceated. Exit is now an event.
Try
Application.Current.Terminate();
you can simply create a button by using XAML and then add this code into your Main page xaml.cs
Application.Current.Exit();
MSDN recommends to not close apps in Windows 8.1:
We recommend that apps not close themselves programmatically unless
absolutely necessary. For example, if an app detects a memory leak, it
can close itself to ensure the security of the user's personal data.
When you close an app programmatically, the system treats this as an
app crash.
https://msdn.microsoft.com/en-us/library/windows/apps/hh464925.aspx#close