// http://m0s-programming.blogspot.com/2011/02/file-upload-in-through-webview-on.html //protected void onActivityResult(int requestCode, int resultCode, // Intent intent) //{ // if (requestCode == FILECHOOSER_RESULTCODE) // { // if (null == mUploadMessage) return; // Uri result = intent == null || resultCode != RESULT_OK ? null // : intent.getData(); // mUploadMessage.onReceiveValue(result); // mUploadMessage = null; // } //} protected override void onCreate(Bundle savedInstanceState) { // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2012/20120-1/201208 // this is a prototype implementation for ApplicationWebService on android // we need to serve assets at random port // we need a webbrowser // web browser works. // while loading we could display jsc logo, made in opengl // we need ip and port. // we need to show what assets we have // let's start using HttpRequest base.onCreate(savedInstanceState); #region assets var assets = this.getResources().getAssets(); var aa = new List<InternalFileInfo>(); //var a = new List<InternalFileInfo>(); Action<string> GetAssets = null; GetAssets = (ParentDirectory) => { var collection = new string[0]; Log.wtf("ApplicationWebService", "GetAssets " + ParentDirectory); try { collection = assets.list(ParentDirectory); } catch { } foreach (var RelativeName in collection) { var FileName = string.IsNullOrEmpty(ParentDirectory) ? RelativeName : ParentDirectory + "/" + RelativeName; var IsFile = false; try { var rr = assets.open(FileName); IsFile = true; rr.close(); } catch { } if (IsFile) { aa.Add( new InternalFileInfo { Name = FileName, } ); } if (FileName == "webkit") { } else if (FileName == "sounds") { } else if (FileName == "images") { } else GetAssets(FileName); } }; GetAssets(""); #endregion #region CreateServer at port var r = new System.Random(); var port = r.Next(1024, 32000); var ip = getLocalIpAddress(); var ipa = Dns.GetHostAddresses(getLocalIpAddress())[0]; CreateServer( this, ipa, port, x => { }, aa.ToArray() ).Start(); #endregion #region uri var uri = "http://" + ip; uri += ":"; uri += ((object)(port)).ToString(); //var height = this.getWindowManager().getDefaultDisplay().getHeight(); //var width = this.getWindowManager().getDefaultDisplay().getWidth(); //if (width > height) //{ // this.ToFullscreen(); //} //else uri += "/jsc?flag=foo#bar"; #endregion #region WebView as UI at uri var webview = new WebView(this); webview.getSettings().setJavaScriptEnabled(true); webview.setWebViewClient(new MyWebViewClient { }); webview.setWebChromeClient( new MyWebChromeClient { //AtopenFileChooser = // (ValueCallback<Uri> uploadMsg) => // { // //mUploadMessage = uploadMsg; // //Intent i = new Intent(Intent.ACTION_GET_CONTENT); // //i.addCategory(Intent.CATEGORY_OPENABLE); // //i.setType("image/*"); // //this.startActivityForResult( // // Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE // //); // } } ); this.setContentView(webview); this.AtKeyDown = (keyCode, e) => { if (keyCode == KeyEvent.KEYCODE_BACK) { if (webview.canGoBack()) { webview.goBack(); return true; } } return false; }; this.setTitle(uri); webview.loadUrl(uri); #endregion }