Very simple UI. Click the button and select image upload (not the main thread) from the picture library.
The code for ANDRIOD main loadactivity is as follows:
public class Loadactivity extends Activity {public static final String tag_string= "loadactivity";p rivate string Pathstri ng=null;static final int flag_load=4;private Button button=null;private useruploadservice service=new Useruploadserviceimpl (); @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_load); button= (Button) This.findviewbyid (R.id.button1); Button.setonclicklistener (New View.onclicklistener () {@Overridepublic void OnClick (View v) {String status = Environment . Getexternalstoragestate (); if (Status.equals (environment.media_mounted)) {//Determine if there is an SD card Intent intent=new Intent (Intent.action_pick, an Droid.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); Startactivityforresult (Intent, flag_load); }}}); } @Override Public boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; Adds items to the action bar if it is present. Getmenuinflater (). Inflate (r.menu.load, menu); return true; } @Override protected void Onactivityresult (int requestcode, int resultcode, Intent data) {Super.onactivityr Esult (Requestcode, ResultCode, data); if (requestcode==flag_load) {if (data==null) {Toast.maketext (this, "You did not select any picture", Toast.length_long). Show (); } else {Uri uri=data.getdata (); if (uri==null) {Toast.maketext (this, "You did not select any picture", Toast.length_long). Show (); else {String path=null; String[] Pojostrings={mediastore.images.media.data}; Cursor cursor=getcontentresolver (). Query (URI, pojostrings, NULL, NULL, NULL); if (cursor!=null) {int col= Cursor.getcolumnindexorthrow (Pojostrings[0]); Cursor.movetofirst ();p ath=cursor.getstring (col); Cursor.close ();} if (path==null) {Toast.maketext (this, "picture path not obtained", Toast.length_long). Show (); else {Toast.maketext (this, "Picture path is" +path, Toast.length_long). Show ();p athstring=path;new ALertdialog.builder (This). Settitle ("hint"). Setmessage ("Do you want to choose this image to upload?"). "). Setpositivebutton (" OK ", new Dialoginterface.onclicklistener () {@Overridepublic void OnClick (Dialogin Terface dialog, int which) {doupload ();}} ). Create (). Show (); }}}}} private void Doupload () {New Thread (new Runnable () {@Overridepublic void R Un () {try {InputStream in=new fileinputstream (New File (pathstring)); Map<string, String>data=new hashmap<string, string> ();d ata.put ("Name", "liuming");d ata.put ("Gender", "Male "); final String retstring=service.userupload (in, data,pathstring); LOG.D (tag_string, retstring);} catch (Exception e) {e.printstacktrace ();//runonuithread (new Runnable () {//public void run () {//toast.maketext ( Loadactivity.this, "Error uploading Update", Toast.length_long). Show ();//}//});}}). Start ();}}
<span style= "font-family:arial, Helvetica, Sans-serif;" >service.userupload (in, data,pathstring) </span>
An interface class implementation that handles the upload logic.
Portal: Click to open link
Andriod file Upload (ii) Android-side UI