Skip to content

Instantly share code, notes, and snippets.

@prashantvc
Created February 22, 2013 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prashantvc/5013207 to your computer and use it in GitHub Desktop.
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
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