java - File browse on Android App -
i want create android app. there form allow users choose files using html tag. there submit button on form, onclick of chosen file should copied android device location on server.
right form on html page , have been using phonegap development.
as of now, have created plugin reads file sdcard folder , using jsch library uploading files on sftp server.
while researching, found many people using following method: form details posted server , using php script file content read using $_files (but not want follow approach)
i need way, when user chooses file using browse option file name picked when form posted.
for e.g below code mainactivity.java file
package com.example.filepicker; import java.io.ioexception; import java.net.uri; import org.apache.cordova.droidgap; import org.apache.http.client.methods.httpget; import android.util.log; import android.view.display; import android.webkit.websettings.renderpriority; import android.view.windowmanager; import android.content.context; import android.database.sqlexception; import android.os.bundle; import android.util.log; import android.view.display; import android.view.menu; public class mainactivity extends /* activity */droidgap { private object request; // @override // protected void oncreate(bundle savedinstancestate) { // super.oncreate(savedinstancestate); // setcontentview(r.layout.activity_main); // } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); super.init(); appview.addjavascriptinterface(this, "mainactivity"); super.loadurl("file:///android_asset/www/index.html"); } public void onformsubmit() { //this method invoked when user clicks form submit button log.i("custom function called", "custom function called"); } }
index.html
<!doctype html> <html> <head> <title>xxxx | index</title> <script type="text/javascript" charset="utf-8" src="js/jquery-1.9.1.js"></script> <script type="text/javascript" charset="utf-8" src="js/cordova.js"></script> <script type="text/javascript" charset="utf-8" src="js/toast.js"></script> <script type="text/javascript" charset="utf-8" src="js/jquery.magnific-popup.min.js"></script> <script type="text/javascript" src="js/jquery.mcustomscrollbar.concat.min.js"></script> <script type="text/javascript" charset="utf-8" src="js/fileuploadplugin.js"></script> <link rel="stylesheet" type="text/css" href="css/style.css" > <link rel="stylesheet" type="text/css" href="css/bootstrap.css" /> <link rel="stylesheet" type="text/css" href="css/media-query.css" /> <link rel="stylesheet" type="text/css" href="css/magnific-popup.css" /> <link rel="stylesheet" type="text/css" href="css/jquery.mcustomscrollbar.css" /> <script type="text/javascript"> // wait device api libraries load // document.addeventlistener("deviceready", ondeviceready, false); // device apis available // function ondeviceready() { alert('device ready'); var fileupload1 = new fileuploadplugin(); var ipaddress = "xxxxxxx"; var userid ="xxx"; var password = "xxx"; /*cordova.exec(onfilesystemsuccess, fail, "fileuploadplugin", "echo", [ipaddress,userid,password]); */ /*cordova.exec(onfilesystemsuccess, fail, "fileuploadplugin", "display", ["def"]); */ /* callnewactivity();*/ alert('after execution called'); } function onfilesystemsuccess(result) { alert('on success'+result); // alert('msg'+msg); // alert('on status'+status); console.log('this success'); /* console.log(result); */ /* console.log(filesystem.name); console.log(filesystem.root.name);*/ } function fail(error) { alert('on failure'+error); console.log('this error'); alert('err code'+evt.target.error.code); /* console.log(evt.target.error.code); */ } function onformsubmit() { window.mainactivity.onformsubmit(); } </script> </head> <body> <div data-role="page"> <div data-role="header"> <h1>attach file</h1> </div> <div data-role="content"> <form id="file-attachment-form" action="http://putyourserverurl"> <div data-role="fieldcontain"> <label for="data">put text:</label> <input name="data" type="text" id="data"/> </div> <div data-role="fieldcontain"> <label for="attachment">attachment:</label> <input type="file" name="attachment" id="attachment"/> </div> <input type="submit" value="submit"/> </form> </div> <script> $('#file-attachment-form').submit(function () { formdata = new formdata($(this)[0]); alert('new '+formdata); /*console.log(formdata);*/ /* $.ajax({ type:'post', url:$('#file-attachment-form').attr('action'), data:formdata, contenttype: false, processdata: false, error:function (jqxhr, textstatus, errorthrown) { alert('failed upload file') }, success:function () { alert('file uploaded') } })*/ /*alert('formdata = '+formdata);*/ onformsubmit(); }); </script> </div> </body> </html>
e.g mainactivity.java file have function called "onformsubmit" function should able read files parameter.
i know if possible method. if not pointer/suggestions helpful.
thanks in advance.
Comments
Post a Comment