Post image to Facebook in JSON format in Android -
i want post image facebook in having json string,i have included static image in string, , works fine, if want add dynamic image can if??
here code:
parameters.putstring( "attachment", "{\"name\":\"" + b.getstring("title") + "\",\"href\":\"" + b.getstring("cmpweb") + "\",\"description\":\"" + desc + "\",\"media\":[{\"type\":\"image\",\"src\":\"http://184.106.227.45/quaddeals/img/small_thumb/deal/692.e6b86fa39f3ba25e29f0351140b57a94.jpg\",\"href\":\"http://alumni.brown.edu/\"}]}");
this value http://184.106.227.45/quaddeals/img/small_thumb/deal/692.e6b86fa39f3ba25e29f0351140b57a94.jpg\" static value want include dynamic content got previous page using intent,say(b.getstring("url")).. want show web link if user click link should shows web view ist static "http://alumni.brown.edu" want include dynamic data..
pls me in advance...
hey use code upload image using json. show u code if form that.
uploadphotoresultdialog.java
public class uploadphotoresultdialog extends dialog { private string response, photo_id; private textview moutput, musefultip; private button mviewphotobutton, mtagphotobutton; private imageview muploadedphoto; private activity activity; private progressdialog dialog; private boolean hidephoto = false; private handler mhandler; public uploadphotoresultdialog(activity activity, string title, string response) { super(activity); this.activity = activity; this.response = response; settitle(title); } @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); mhandler = new handler(); setcontentview(r.layout.upload_photo_response); layoutparams params = getwindow().getattributes(); params.width = layoutparams.fill_parent; params.height = layoutparams.fill_parent; getwindow().setattributes((android.view.windowmanager.layoutparams) params); moutput = (textview) findviewbyid(r.id.apioutput); musefultip = (textview) findviewbyid(r.id.usefultip); mviewphotobutton = (button) findviewbyid(r.id.view_photo_button); mtagphotobutton = (button) findviewbyid(r.id.tag_photo_button); muploadedphoto = (imageview) findviewbyid(r.id.uploadedphoto); jsonobject json; try { json = util.parsejson(response); final string photo_id = json.getstring("id"); this.photo_id = photo_id; moutput.settext(json.tostring(2)); musefultip.settext(activity.getstring(r.string.photo_tip)); linkify.addlinks(musefultip, linkify.web_urls); mviewphotobutton.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { if(hidephoto) { mviewphotobutton.settext(r.string.view_photo); hidephoto = false; muploadedphoto.setimagebitmap(null); } else { hidephoto = true; mviewphotobutton.settext(r.string.hide_photo); /* * source tag: view_photo_tag */ bundle params = new bundle(); params.putstring("fields", "picture"); dialog = progressdialog.show(activity, "", activity.getstring(r.string.please_wait), true, true); dialog.show(); utility.masyncrunner.request(photo_id, params, new viewphotorequestlistener()); } } }); mtagphotobutton.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { /* * source tag: tag_photo_tag */ settag(); } }); } catch (jsonexception e) { settext(activity.getstring(r.string.exception) + e.getmessage()); } catch (facebookerror e) { settext(activity.getstring(r.string.facebook_error) + e.getmessage()); } } public void settag() { string relativepath = photo_id +"/tags/" + utility.useruid; bundle params = new bundle(); params.putstring("x", "5"); params.putstring("y", "5"); utility.masyncrunner.request(relativepath, params, "post", new tagphotorequestlistener(), null); } public class viewphotorequestlistener extends baserequestlistener { public void oncomplete(final string response, final object state) { try { jsonobject json = util.parsejson(response); final string pictureurl = json.getstring("picture"); if(textutils.isempty(pictureurl)) { settext("error getting \'picture\' field of photo"); } else { mhandler.post(new runnable() { public void run() { new fetchimage().execute(pictureurl); } }); } } catch (jsonexception e) { dialog.dismiss(); settext(activity.getstring(r.string.exception) + e.getmessage()); } catch (facebookerror e) { dialog.dismiss(); settext(activity.getstring(r.string.facebook_error) + e.getmessage()); } } public void onfacebookerror(facebookerror error) { dialog.dismiss(); settext(activity.getstring(r.string.facebook_error) + error.getmessage()); } } public class tagphotorequestlistener extends baserequestlistener { public void oncomplete(final string response, final object state) { if (response.equals("true")) { string message = "user tagged in photo @ (5, 5)" + "\n"; message += "api response: " + response; settext(message); } else { settext("user not tagged."); } } public void onfacebookerror(facebookerror error) { settext(activity.getstring(r.string.facebook_error) + error.getmessage()); } } public void settext(final string txt) { mhandler.post(new runnable() { public void run() { moutput.settext(txt); } }); } private class fetchimage extends asynctask<string, void, bitmap> { protected bitmap doinbackground(string... urls) { return utility.getbitmap(urls[0]); } protected void onpostexecute(bitmap result) { dialog.dismiss(); muploadedphoto.setimagebitmap(result); } } }
and xml fiel :
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/black"> <textview android:id="@+id/apioutputlabel" android:text="@string/api_response" android:textcolor="@color/white" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingtop="3dp" android:paddingleft="3dp" /> <scrollview android:id="@+id/scrollview01" android:layout_height="wrap_content" android:layout_width="fill_parent" android:paddingbottom="3dp"> <textview android:id="@+id/apioutput" android:textcolor="@color/white" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingtop="3dp" android:paddingleft="3dp" android:background="@color/grey" /> </scrollview> <view android:paddingtop="3dp" android:layout_width="fill_parent" android:layout_height="2dip" android:background="@color/grey" /> <linearlayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <button android:id="@+id/view_photo_button" android:text="@string/view_photo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" /> <button android:id="@+id/tag_photo_button" android:text="@string/tag_photo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" /> </linearlayout> <imageview android:id="@+id/uploadedphoto" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingtop="3dp" android:paddingbottom="3dp" /> <textview android:id="@+id/tip_label" android:text="@string/tip_label" android:textcolor="@color/white" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingtop="3dp" android:paddingleft="3dp" /> <textview android:id="@+id/usefultip" android:textcolor="@color/white" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingtop="5dp" android:paddingleft="3dp" /> </linearlayout>
Comments
Post a Comment