Hi,
I am trying to develop an app which basically opens a web page, which also offers the possibility to download and upload stuff, including i.d. photos for an accreditation system. It is basically a web browser hard coded to open a particular address.
Everything works smoothly, except the upload photo part.
I have tried to write the app using android studio, in JAVA (even though I know very little in terms of java) , and later using Visual Studio for MAC, with more or less the same result. The app works flawlessly, except for the uploading part.
With the android studio app, the "Upload button" is simply ignored, while with the Visual Studio (Xamarin) version, the first time the button is clicked, the file browser opens on android, but the image is not actually uploaded. Hitting the upload button the second, third, fourth time is simply ignored by the app, no errors in console no nothing.
I am completely stumped, this should be easy, The page works perfectly in chrome and other mobile browsers, just not in the webview app.
I have done a lot of searching on Google, and found a number of workarounds, some of which are really scary for a simple app like this, but still none of them seem to work.
For testing purposes, I have setup a simple page to test my app, "http://test.johannfenech.com/test.html". It works with all major browsers. (it will only accept images of up to a couple of Mb's)
This is my main class (My_Web.CC.cs) :-
using Android.App;
using Android.Content;
using Android.OS;
using Android.Webkit;
namespace portal.Droid {
[Activity(Label = "Web View Test", MainLauncher = true, Theme = "@android:style/Theme.NoTitleBar")]
public class My_Webview : Activity {
WebView web_view;
protected override void OnCreate(Bundle bundle) {
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
web_view = FindViewById<WebView>(Resource.Id.webview);
web_view.SetWebViewClient(new WebViewClient());
web_view.SetWebChromeClient(new My_Web_CC(this));
web_view.Settings.JavaScriptEnabled = true;
web_view.LoadUrl("http://test.johannfenech.com/test.html");
}
// Handle Back Key
public override bool OnKeyDown(Android.Views.Keycode keyCode, Android.Views.KeyEvent e) {
if (keyCode == Android.Views.Keycode.Back && web_view.CanGoBack()) {
web_view.GoBack();
return true;
}
return base.OnKeyDown(keyCode, e);
}
}
partial class My_Web_CC : WebChromeClient {
private IValueCallback mUploadMessage;
private static int FILECHOOSER_RESULTCODE = 1;
private My_Webview thisActivity = null;
public My_Web_CC(My_Webview context) {
thisActivity = context;
}
//For Android 4.1
[Java.Interop.Export]
public void openFileChooser(IValueCallback uploadMsg, Java.Lang.String acceptType, Java.Lang.String capture) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ActionGetContent);
i.AddCategory(Intent.CategoryOpenable);
i.SetType("image/*");
thisActivity.StartActivityForResult(Intent.CreateChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);
}
}
}
My AndroidManifest.xml :-
<?xml version="1.0" encoding="utf-8"?>
I would be grateful if anyone could shed some light on what am I doing wrong
Thank You
J