Facebook and Android sdk -
i want share image, on phone's sd card, on facebook.
my problem after run application can see following message
myapplication access public profile , friend list.
but when press ok , go facebook page can not see images there.
i following instructions on this link , code below
public class photoactivity extends basefragmentactivity { private static final string mime_type = "image/jpeg"; private uri uri; private imageview mphotoview; private session.statuscallback mstatuscallback = new sessionstatuscallback(); private boolean mposttowall = false; private imagebutton retakebtn; private class sessionstatuscallback implements session.statuscallback { @override public void call(session session, sessionstate state, exception exception) { if (session.isopened() && mposttowall) { share(); } } } @override public void onstart() { super.onstart(); session.getactivesession().addcallback(mstatuscallback); } @override public void onstop() { super.onstop(); session.getactivesession().removecallback(mstatuscallback); } @override public void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); session.getactivesession().onactivityresult(this, requestcode, resultcode, data); } @override protected void onsaveinstancestate(bundle outstate) { super.onsaveinstancestate(outstate); session session = session.getactivesession(); session.savesession(session, outstate); } private void share() { bundle bundle = new bundle(); mphotoview.setdrawingcacheenabled(true); mphotoview.builddrawingcache(); bitmap bmap = mphotoview.getdrawingcache(); bytearrayoutputstream stream = new bytearrayoutputstream(); bmap.compress(bitmap.compressformat.jpeg, 80, stream); byte[] bytearray = stream.tobytearray(); bundle.putbytearray("picture", bytearray); webdialog feeddialog = ( new webdialog.feeddialogbuilder(getapplicationcontext(), session.getactivesession(), bundle)) .setoncompletelistener(new oncompletelistener() { @override public void oncomplete(bundle values, facebookexception error) { if (error == null) { // when story posted, echo success // , post id. final string postid = values.getstring("post_id"); if (postid != null) { toast.maketext(getapplicationcontext(), "posted story, id: "+postid, toast.length_short).show(); } else { // user clicked cancel button toast.maketext(getapplicationcontext(), "publish cancelled", toast.length_short).show(); } } else if (error instanceof facebookoperationcanceledexception) { // user clicked "x" button toast.maketext(getapplicationcontext(), "publish cancelled", toast.length_short).show(); } else { // generic, ex: network error toast.maketext(getapplicationcontext(), "error posting story", toast.length_short).show(); } } }) .build(); feeddialog.show(); } @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); settheme(r.style.apptheme); uri = getintent().getdata(); setcontentview(r.layout.activity_photo); retakebtn = (imagebutton) findviewbyid(r.id.retake_btn); string lang = getstring(r.string.lang); if (lang.endswith("fr")) { retakebtn.setimageresource(r.drawable.retake_xhdpi); } else { retakebtn.setimageresource(r.drawable.retake_en_xhdpi); } // facebook settings.addloggingbehavior(loggingbehavior.include_access_tokens); session session = session.getactivesession(); if (session == null) { if (savedinstancestate != null) { session = session.restoresession(this, null, mstatuscallback, savedinstancestate); } if (session == null) { session = new session(this); } session.setactivesession(session); if (session.getstate().equals(sessionstate.created_token_loaded)) { session.openforpublish(new session.openrequest(photoactivity.this) .setcallback(mstatuscallback).setpermissions(arrays.aslist("photo_upload","publish_stream","publish_actions"))); } } mphotoview = (imageview) findviewbyid(r.id.photo); mphotoview.setimageuri(uri); retakebtn.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { intent intent = new intent(photoactivity.this, cameraactivity.class); startactivity(intent); finish(); } }); } @override public boolean oncreateoptionsmenu(com.actionbarsherlock.view.menu menu) { com.actionbarsherlock.view.menuinflater inflater = getsupportmenuinflater(); inflater.inflate(r.menu.item_photo_activity, menu); return super.oncreateoptionsmenu(menu); } @override public boolean onoptionsitemselected( com.actionbarsherlock.view.menuitem item) { switch (item.getitemid()) { case android.r.id.home: intent intent = new intent(photoactivity.this, cameraactivity.class); intent.putextra("from_activity", 300); startactivity(intent); finish(); break; case r.id.share_button: session session = session.getactivesession(); if (!session.isopened() && !session.isclosed()) { session.openforpublish(new session.openrequest(photoactivity.this) .setcallback(mstatuscallback).setpermissions(arrays.aslist("photo_upload","publish_stream","publish_actions"))); } else { session.openactivesession(photoactivity.this, true, mstatuscallback); } break; } return true; }
you're trying add photo feed dialog, not take binary data. see feed dialog documentation here, "picture" parameter takes url.
if want upload photo, need "publish_actions" permission, , call request.newuploadphotorequest method. have @ hello facebook sample app that's shipped sdk, demonstrates how upload photo.
Comments
Post a Comment