Share Target and JumpListItemBackgroundConverter - windows-phone-8.1

I've added the Share Target declaration to my app for the data format WebLink and everything works as expected. However, when I add a JumpListItemBackgroundConverter or JumpListItemForegroundConverter anywhere in the app, the app hangs on the splash screen when you enter the app using the Share from IE. No exception, no crash, the debugger doesn't even stop. All I get is a cryptic error in the output window, "The program '...' has exited with code -1073741819 (0xc0000005) 'Access violation'." The documentation for those converters say they're fine with universal apps, just that they've been moved to a different namespace. Has anyone been able to get these two things to work in the same app? If so, where did I go wrong? Or is there something better than those two converters to get the LongListSelector look and feel?
Steps to reproduce:
Create a new universal app. I chose hub.
Add a share target of format WebLink to the appxmanifest declarations.
Add a new page to point the share contract to.
Add the OnShareTargetActivated code to app.xaml.cs to open the new page. See code below
Add a JumpListItemBackgroundConverter to the resources of the main page of the app. You don't need to apply it to anything, just declaring it is enough to break the sharing.
Go to IE and share a link. It should hang on the splash screen.
Code for app.xaml.cs:
protected override async void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
{
// Replace SharePage with the name of the share target page
var rootFrame = new Frame();
rootFrame.Navigate(typeof(SharePage), args.ShareOperation);
Window.Current.Content = rootFrame;
Window.Current.Activate();
}

It turns out this is a bug in the emulator. It works if you test on a physical device.
MSDN Forum - JumpListItemBackgroundConverter and Share Target in Windows Phone 8.1

Related

DisplayRootView Crashing with an AV (v2.0.0.0 stable) on WP81 WinRT Stack

The program '[3188] Sprudelsuche.WP.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'.
This is the last line in Output, before that I get
'Sprudelsuche.WP.exe' (CoreCLR: .): Loaded 'C:\windows\system32\en-US\mscorlib.debug.resources.dll'. Module was built without symbols.
[Caliburn.Micro.View] ERROR: System.NullReferenceException: Object reference not set to an instance of an object.
at Caliburn.Micro.View.SetContentPropertyCore(Object targetLocation, Object view)
Effect is that app shows splash briefly, then closes immediately.
The application in question is on GitHub at https://github.com/christophwille/Sprudelsuche/blob/master/Source/Sprudelsuche.WP/App.xaml.cs - the reason I started trying DisplayRootView is that DisplayRootViewFor doesn't work with navigation later in the app (MainViewModel/NavigateTo: Output shows it is activating the new view model, but the view never comes up).
I use CM in a WP8 SL app with no issues whatsover. However, this has me stumped as I didn't deviate much from the CM samples in this very simple port. (btw, NavigateToViewModel exhibits the same issue)
Bootnote: I noticed a interesting tidbit in the source code for DisplayRootView - handling of the frame after navigation compared to DisplayRootViewFor. Also, in the Hub the convention based binding didn't work for me. I sure am doing something wrong...
look at your line of code in PrepareViewFirst(Frame rootFrame)
you have
protected override void PrepareViewFirst(Frame rootFrame)
{
container.RegisterNavigationService(this.RootFrame);
}
it probably should be
protected override void PrepareViewFirst(Frame rootFrame)
{
container.RegisterNaviationService(rootFrame);
}
then
DisplayRootView<MainView>();
should work just fine;
edit:
try moving PrepareViewFirst() method to the bottom of the Configure override. There are 2 PrepareViewFirst() methods one parameterized and the other not... use the un-param'd method in Configure(), comment out the call in OnLaunched();
In writing comments to mvermef's answer I started trying out copying code to a blank project / using a different view for startup. As this worked a-ok, my remark "binding doesn't work" reminded me that I tried a hell lot of different approaches to make it work, and lo and behold, one of those had remained in the source code:
<Hub Header="spritpreise">
<HubSection Header="SUCHE">
<DataTemplate>
<Grid caliburn:View.Model="{Binding}">
The AV crash was caused by the last line. Turning it back into a Grid without the CM-VM-binding made the app work. Funny though that this only crashes View-first, and not ViewModel-first.

Showing m.bing.com in the WP8 WebBrowser control

I'm having a problem getting bing.com to load in a WebBrowser control on Windows Phone 8. It seems that doing that will launch the WP8 Search App (same as pressing the Search button on the phone). The problem is, once you click a result in that search app, it doesn't take you back to your original app - it goes to IE to show the result. This isn't going to work for me and seems to be a massive flaw (IMO) in the WebBrowser behavior.
There does seem to be a few apps out there that have succeeded in being able to show bing.com without launching the phone's search app - for example Image Downloader Free. There was another one, but I can't remember what it was...
After some research, I've found that the WebBrowser_Navigating event gets fired 3 times when going to bing.com: first request to the user-entered URL (www.bing.com), it then gets redirected to http://wp.m.bing.com/?mid=10006, then it redirects to bing://home/?mid=10006.
Preventing it from forwarding to the Bing search app is quite simple, just add this to the Navigating event:
e.Cancel = (e.Uri.Scheme == "bing");
The problem is, it then only shows the Bing search page place holder which says "Bing Search" and has a link that says "Back to Bing search" which does nothing (it would typically relaunch the Bing Search app).
I have a few thoughts, but I'm not sure how feasible they are.
In the WP8 WebBrowser control, is it possible to fake the User Agent?
Can one of the items in the WebBrowser.Uri.Flags property be removed or added to affect the way Bing.com handles the request?
If none of those work, I can simply create a dummy page on my web server, redirect all bing.com requests to it, and have it grab the m.bing.com front page with a card-coded user-agent. I really would like to avoid having to do this option though. From an End-User perspective, they would never know, but I just added a whole new layer of overhead, maintenance and resource-wise.
If you're interested, attached are the diff's for the EventArgs object between the 3 requests that occur in the WebBrowser.Navigating event:
Request 1 (bing.com) -> Request 2 (forwarded to wp.m.bing.com/?mid=10006)
Request 2 (forwarded to wp.m.bing.com/?mid=10006) -> Request 3 (forwarded to bing://home/?mid=10006)
tl;dr Does anyone know of a way to prevent www.bing.com from causing the search app to launch in the WebBrowser control in my application?
Thank you!
I don't know if there's a better way to handle this, but I found a solution. I haven't gotten it to work perfectly when the back button is clicked, so I will update my answer if/when I found a more solid solution. I still think this is a big flaw in the WebBrowser control in WP8.
Here is the code:
private bool _customHeaderRequest = false;
private void MainBrowser_Navigating(object sender, NavigatingEventArgs e)
{
string host = e.Uri.Host.ToLowerInvariant().Trim();
if ((host == "bing.com" || host.EndsWith(".bing.com")) && !_customHeaderRequest)
{
e.Cancel = true;
Dispatcher.BeginInvoke(() =>
MainBrowser.Navigate(e.Uri, null,
"User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; Lumia 710)\r\n"));
_customHeaderRequest = true;
return;
}
_customHeaderRequest = false;
}
private void MainBrowser_Navigated(object sender, NavigationEventArgs e)
{
_customHeaderRequest = false;
}
I don't have access to my emulator, but I tried it on my phone, and:
The redirect doesn't happen when you "Prefer desktop version" and open m.bing.com. Warning: The mobile version isn't very pretty.
Try disabling scripts on your WebBrowser, that could stop the redirect from happening.
Any chance you could just use Google?

Unhandled exception when firing WinRT 8.1 WebView ScriptNotify

I'm trying to create an MVVM Caliburn-based WinRT 8.1 app (I know that CM won't be perfectly compatible with 8.1 until version 2.0 is out, but the error does not seem to be related, as it is raised also when the handler is placed in the view code behind). One of its views contains a WebView control, whose content is set via NavigateToString (HTML contents come from app's installed assets). The HTML loaded into this control includes several hyperlinks, most of them representing cross-references to other asset-based HTML content. So when users click the link I want to override the standard navigation action, get my viewmodel notified, and let it load another HTML content from the app assets.
Here is what I did, following the post Open links in external browser in WebView (WinRT):
in the XAML code, I added to the WebView control an attribute for attaching the ScriptNotify event to my VM: cal:Message.Attach="[Event ScriptNotify] = [Action GetFromLink($eventArgs)]" (see https://caliburnmicro.codeplex.com/wikipage?title=All%20About%20Actions).
in my VM, the method signature is public void GetFromLink(NotifyEventArgs e).
whenever my VM loads some HTML into the WebView, it first injects a script in the HTML head which replaces the click handler of each anchor representing a cross-reference (all these anchors are marked by a class="xref" attribute). This script is hold in a constant in my VM:
private const string SCRIPT = "for (var i = 0; i < document.links.length; i++) {" +
"var className = document.links[i].getAttribute(\"class\");" +
"if (className && className === \"xfer\") {" +
"document.links[i].onclick = function() {" +
"window.external.notify('url:' + this.href);" +
"return false;" +
"}}}";
Now, when I launch the app, load an item containing one of these xref's and click on it, I get an unhandled exception telling me that "navCancelInit is undefined". I suppose this error is surfacing from JS code, but I cannot see where and how this function should be defined.
According to http://msdn.microsoft.com/library/windows/apps/br227713, I do not need any additional step for ScriptNotify when HTML has been loaded via NavigateToString. Could anyone suggest a solution?
I got an answer from a MS guy about this, so credit is not mine for this answer: it is a timing issue. I must ensure that the page has fully loaded before running the script which changes the DOM; pretty simple, if you think. Just moving the script at the end of the page, or wrapping it in an onload handler, should make the trick. Hope this can save some hair-pulling to others!
If you listen to this event: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.webview.domcontentloaded.aspx WebView.DOMContentLoaded event, All of the script should be loaded in the WebView and you should be able to access and execute, if you are trying to do this before the scripts won't be loaded.

Actionscript works when tested in flash, but not on html page?

I am trying to create an ad for a website. When someone clicks on the ad, it is supposed to redirect them to a website, and register the click with google analytics.
I have done this with the following script:
import flash.external.ExternalInterface;
movieClip_3.addEventListener(MouseEvent.CLICK, onClick);
function onClick(event:MouseEvent):void {
trace("hi");
ExternalInterface.call("console.log", "test");
//ExternalInterface.call("_gaq._trackPageview", "/vpv/annoncer/[firmanavn.dk]");
navigateToURL(new URLRequest("http://www.google.com"), "_blank");
}
When i run this using preview->flash and i click on the surface, (where there is a big red square called movieClip_3) It opens the webpage. However when i try to publish as html, the big red square shows, but nothing happens on click. Not even console.log. I have tried setting allowscriptaccess = always but that does not change anything.
Can you guys help me? Any help is appreciated.
Security problems?
Developers should validate all URLs before passing them to this
function.
For local content running in a browser, calls to the navigateToURL()
method that specify a "javascript:" pseudo-protocol (via a URLRequest
object passed as the first parameter) are only permitted if the SWF
file and the containing web page (if there is one) are in the
local-trusted security sandbox. Some browsers do not support using the
javascript protocol with the navigateToURL() method. Instead, consider
using the call() method of the ExternalInterface API to invoke
JavaScript methods within the enclosing HTML page.
source: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/package.html#navigateToURL()
EDIT:
Since javascript is not permitted out of the sandbox, you can try with ExternalInterface:
ExternalInterface.call("javascript_functionname", "mypage.html");
In the parameters for publishing:
'allowScriptAccess', 'always',
You can only test this on your server not locally.
I'd suggest double checking the security settings (right click on flash container->Global Settings-> Advanced -> Trusted Location Settings). Also make sure your html file contains the javascript function you're trying to execute and look for blocked pop-up notifications in the browser. Maybe you just don't allow pop-ups to run.

StageWebView Lack on URLs with target="_blank"

is there any solution on StageWebView.loadURL(), how I can handle URLs in HTML Pages which have target="_blank"?
It's a mobile Android App. (TabbedViewApplication)
Hope someone can help.
Thx
One option is StageWebViewBridge.
StageWebViewBridge is an extended version of flash.media.StageWebView.
Extends loadString method with AS3 - JS communication.
-Extends Bitmap class, you can modify his x,y,alpha,rotation,visible, etc ( Version 1 Beta )
-Communicates Actionscript with Javascript.
-Communicates Javascript with Actionscript.
-Load local files and resources in a easy way.
-Extends loadString method with AS3 - JS communication.
-Extends loadString method to load local resources.
-Lets you take an SnapShot to use as the bitmapData of the bitmap.
StageWebViewBridge source: https://code.google.com/p/stagewebviewbridge/
I never worked with the StageWebView but I know it's really limited. When using an HTMLLoader, you can set a custom HTMLHost instance that specifies to use current HTMLLoader when opening to _blank. However, I don't think it's possible with StageWebView.
public class MyHTMLHost extends HTMLHost
{
public function MyHTMLHost(defaultBehaviors:Boolean=false)
{
super(defaultBehaviors);
}
override public function createWindow(windowCreateOptions:HTMLWindowCreateOptions):HTMLLoader
{
// all JS calls and HREFs to open a new window should use the existing window
return htmlLoader;
}
}
OK, so the only solution for this problem i could found is to load the page (containing the links) as String with the URLLoader and replace its specified parts. Finally loading it via StageWebView.loadString() method.
Problems occur when the Site is dynamic and contains JavaScript. I had also replace some relative links with absolute pathes.
That's it... but I really hope that adobe makes it possible to load those "_blank" links with the StageWebView.loadURL() method.
If you want to capture when a user clicks on a link inside your StageWebView add an an event listener for location changing event (LocationChangeEvent).
This LocationChangeEvent will include the URL they are going to and target. Then you can prevent the URL from loading, let it continue (by doing nothing) or handle it any other way including loading another URL.
If you want to load another URL first stop the loading with stageWebView.stop(). You should also call event.preventDefault(). You can then attempt to
Note: There is another event called locationChange that may be helpful.
As it was declared as an official bug, adobe QA Owner Sanjay C. added a comment: "Able to reproduce the issue with the attached project. Sending to IRB."
So, hope the next Build will come up with the fix wit it.
Best regards