java - How to use android-async-http library -
i trying use android-async-http library asynchronous file upload server. callback inside method call upload. however, error when trying call method asynctask class. can spot getting error? here upload method:
public void upload(string title, string genre, string description, string songuri, int accountid) { file song = new file(songuri); try { string url = uri.parse(getresources().getstring(r.string.audio_upload_url)) .buildupon() .appendqueryparameter("title", title) .appendqueryparameter("tags", genre) .appendqueryparameter("description", description) .appendqueryparameter("accountid", string.valueof(accountid)) .build().tostring(); asynchttpresponsehandler httpresponsehandler = createhttpresponsehandler(); requestparams params = new requestparams(); // path retrieved library or camera //string imagefilepath = "/storage/sdcard/dcim/camera/img.jpg"; //params.put("data", new file(imagefilepath)); params.put("song", song); asynchttpclient client = new asynchttpclient(); client.post(url, params, httpresponsehandler); } catch (ioexception e) { e.printstacktrace(); } }
and here how initialize asynchttpresponsehandler class.
public asynchttpresponsehandler createhttpresponsehandler() { asynchttpresponsehandler handler = new asynchttpresponsehandler() { @override public void onstart() { super.onstart(); } @override public void onprogress(int position, int length) { super.onprogress(position, length); // progressbar.setprogress(position); //progressbar.setmax(length); } @override public void onfinish() { super.onfinish(); } @override public void onsuccess(int i, header[] headers, byte[] bytes) { } @override public void onfailure(int i, header[] headers, byte[] bytes, throwable throwable) { } }; return handler; }
and in asynctask class, how calling upload method.
@override protected uploadfragment doinbackground(uploadfragment... params) { string title = titleet.gettext().tostring(); string description = descriptionet.gettext().tostring(); int user_id; userdetails = sessionmanager.getuserdetails(); user user = userdetails.get(0); user_id = user.getuserid(); upload(title, "genre", description, songpath, user_id); return null; }
i error in last line of onpreexecute method of asynctask class because of leaked window, implies getting error when executing doinbackground() method.
use volley library network communication referred google . in android-async-http-library can't cancel particular request possible volley.
Comments
Post a Comment