Directly on the code, realize the WebView powerful function.
Webview.setwebchromeclient (webchromeclient);
Private String Mcamerafilepath = null;private valuecallback<uri> muploadmessage;//form data information private final static int Filechooser_resultcode = result callback for 1;//form </span>
<span style= "FONT-SIZE:18PX;" >private webchromeclient webchromeclient = new Webchromeclient () {//for Android 3.0+public void Openfilechooser (Value Callback<uri> uploadmsg) {if (uploadmsg = = null) {return;} Muploadmessage = uploadmsg;intent i = new Intent (intent.action_get_content); i.addcategory (intent.category_openable); I.settype ("image/*"); Activity.startactivityforresult (Intent.createchooser (i, "File Chooser"), Filechooser_ ResultCode);} For Android 3.0+public void Openfilechooser (Valuecallback uploadmsg, String accepttype) {if (uploadmsg = = null) {return ;} Muploadmessage = uploadmsg;intent i = new Intent (intent.action_get_content); i.addcategory (intent.category_openable); I.settype ("*/*"); Activity.startactivityforresult (Intent.createchooser (i, "File Browser"), Filechooser_resultcode) ;} For Android 4.1public void Openfilechooser (valuecallback<uri> uploadmsg,string accepttype, String capture) {if ( Uploadmsg = = null) {return;} Muploadmessage = uploadmsg;intent i = new InteNT (intent.action_get_content); i.addcategory (intent.category_openable); I.settype ("image/*"); Activity.startactivityforresult (Intent.createchooser (i, "File Chooser"), Filechooser_resultcode);} Private Intent createdefaultopenableintent () {//Create and return a chooser with the default openable//actions including The camera, camcorder and sound//recorder where available. Intent i = new Intent (intent.action_get_content); i.addcategory (intent.category_openable); I.settype ("*/*"); Intent Chooser = Createchooserintent (Createcameraintent (), Createcamcorderintent (), createsoundrecorderintent ()); Chooser.putextra (intent.extra_intent, i); return chooser;} Private Intent createchooserintent (Intent ... intents) {Intent chooser = new Intent (intent.action_chooser); Chooser.putextra (intent.extra_initial_intents, INTENTS); Chooser.putextra (Intent.extra_title, "File chooser"); Return chooser;} Private Intent createcameraintent () {Intent cameraintent = new Intent (mediastore.action_image_capture); File Externaldatadir= Environment.getexternalstoragepublicdirectory (ENVIRONMENT.DIRECTORY_DCIM); System.out.println ("Externaldatadir:" + externaldatadir); File Cameradatadir = new file (Externaldatadir.getabsolutepath () + File.separator + "Browser-photo"); Cameradatadir.mkdirs (); mcamerafilepath = Cameradatadir.getabsolutepath () + file.separator+ System.currentTimeMillis () + ". jpg"; System.out.println ("Mcamerafilepath:" + Mcamerafilepath); Cameraintent.putextra (Mediastore.extra_output, Uri.fromfile (New File (Mcamerafilepath))); return cameraintent;} Private Intent createcamcorderintent () {return new Intent (mediastore.action_video_capture);} Private Intent createsoundrecorderintent () {return new Intent (MediaStore.Audio.Media.RECORD_SOUND_ACTION);};
public void Onactivityresult (int requestcode, int resultcode, Intent Intent) {if (Requestcode = = Filechooser_resultcode) { if (null = = Muploadmessage) return; Uri result = Intent = = NULL | | ResultCode! = ACTIVITY.RESULT_OK? Null:intent.getData (); if (result = = NULL && Intent = = null&& ResultCode = = ACTIVITY.RESULT_OK) {File came Rafile = new File (Mcamerafilepath), if (Camerafile.exists ()) {result = Uri.fromfile (camerafile); activity.sendbroadcast (New Intent (intent.action_media_scanner_scan_file, result));}} Muploadmessage.onreceivevalue (result); muploadmessage = null;} }
Android webview for images, file uploads and start-up camera functions