Created
February 22, 2013 12:53
-
-
Save prashantvc/5013207 to your computer and use it in GitHub Desktop.
WebView - URL mechanism is broken - passing parameters does not work. http://code.google.com/p/android/issues/detail?id=17535#c100
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using Android.App; | |
using Android.Content; | |
using Android.Content.Res; | |
using Android.OS; | |
using Android.Runtime; | |
using Android.Views; | |
using Android.Webkit; | |
using Android.Widget; | |
namespace WebViewTest | |
{ | |
class AssetIncludeWorkaround:WebViewClient | |
{ | |
Context context; | |
public AssetIncludeWorkaround (Context context) | |
{ | |
this.context = context; | |
} | |
public override WebResourceResponse ShouldInterceptRequest (WebView view, string url) | |
{ | |
var stream = InputStreamForAndroidResource (url); | |
if (stream != null) { | |
return new WebResourceResponse (null, null, stream); | |
} | |
return base.ShouldInterceptRequest (view, url); | |
} | |
Stream InputStreamForAndroidResource (string url) | |
{ | |
const string AndroidAsset = "file:///android_asset"; | |
if (url.Contains (AndroidAsset)) { | |
url = url.Replace (AndroidAsset, string.Empty); | |
try { | |
var assetManager = context.Assets; | |
Android.Net.Uri uri = Android.Net.Uri.Parse(url); | |
var fileName = Path.GetFileName(uri.Path); | |
var stream = assetManager.Open (fileName, Access.Streaming); | |
return stream; | |
} catch (Exception ex) { | |
} | |
} | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment