android - Image is missing while sharing the post to Facebook -
i making application need share image text on facebook timeline. code can share text facebook wall image missing while sharing. tried of code of stack overflow. not succeed yet. here code.i used video reference https://www.youtube.com/watch?v=esw5rat9m2c&index=11&list=ple425d66f454d6afa.
package com.example.test2; import java.io.ioexception; import java.net.malformedurlexception; import java.net.url; import com.facebook.android.dialogerror; import com.facebook.android.facebook; import com.facebook.android.facebook.dialoglistener; import com.facebook.android.facebookerror; import android.os.bundle; import android.app.activity; import android.content.intent; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.adapterview; import android.widget.adapterview.onitemclicklistener; import android.widget.adapterview.onitemselectedlistener; import android.widget.arrayadapter; import android.widget.imageview; import android.widget.listview; import android.widget.spinner; import android.widget.textview; import android.widget.toast;
public class mainactivity extends activity {
string[] shareoption; spinner shareoptionlist; int driverstarscore = 1; //2 or 3 ... facebook fb; listview list; string[] shareitemname ={ "dropbox", "email", "facebook", "google plus", "twitter", "whatsapp", }; integer[] shareimageid={ r.drawable.ic_dropbox, r.drawable.ic_email, r.drawable.ic_facebook, r.drawable.ic_googleplus, r.drawable.ic_twitter, r.drawable.ic_whatsapp, }; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); string app_id=getstring(r.string.app_id); fb=new facebook(app_id); shareoptionlist=(spinner) findviewbyid(r.id.spinner_sharescore); shareoption=getresources().getstringarray(r.array.sharechooseoption); arrayadapter<string> adapter1=new arrayadapter<string>(this,android.r.layout.simple_spinner_item,shareoption); shareoptionlist.setadapter(adapter1); shareoptionlist.setonitemselectedlistener(new onitemselectedlistener(){ @override public void onitemselected(adapterview<?> arg0, view arg1, int arg2, long arg3) { // todo auto-generated method stub int index=arg0.getselecteditemposition(); toast.maketext(getbasecontext(), "you select "+ shareoption[index],toast.length_long).show(); } @override public void onnothingselected(adapterview<?> parent) { // todo auto-generated method stub } }); sharelistadapter adapter=new sharelistadapter(this, shareitemname, shareimageid); list=(listview)findviewbyid(r.id.listview_share); list.setadapter(adapter); list.setonitemclicklistener(new onitemclicklistener() { @suppresswarnings("deprecation") @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { // todo auto-generated method stub string selecteditem= shareitemname[+position]; toast.maketext(mainactivity.this, selecteditem, toast.length_short).show(); if(selecteditem=="facebook"){ bundle params=new bundle(); params.putstring("name", "asses me"); params.putstring("caption", "my driving score"); params.putstring("link", "http://www.mybringback.com/"); params.putstring("picture", "http://media-cerulean.cursecdn.com/attachments/8/944/1star.png"); fb.dialog(mainactivity.this, "feed", params, new dialoglistener(){ @override public void onfacebookerror(facebookerror e){ } @override public void onerror(dialogerror e){ //todo auto-generated method stub } @override public void oncancel(){ //todo auto-generated method stub } @override public void oncomplete(bundle values) { // todo auto-generated method stub } }); } if(selecteditem=="email"){ intent email = new intent(intent.action_send); email.settype("message/rfc822"); email.putextra(intent.extra_email , new string[]{"recipient@example.com"}); // if want add email address also. email.putextra(android.content.intent.extra_text, "sample text"); email.putextra(intent.extra_subject, "driving score email"); try { startactivity(intent.createchooser(email, "send mail...")); } catch (android.content.activitynotfoundexception ex) { toast.maketext(mainactivity.this, "there no email clients installed.", toast.length_short).show(); } } } }); } @override public boolean oncreateoptionsmenu(menu menu) { getmenuinflater().inflate(r.menu.main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. return super.onoptionsitemselected(item); } }
androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.test2" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="16" android:targetsdkversion="18" /> <uses-permission android:name="android.permission.internet"/> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name=".mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name=".menu" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.menu" /> <data android:mimetype="image/*" /> <category android:name="android.intent.category.default" /> </intent-filter> </activity> </application> </manifest>
try :
bundle params = new bundle(); params.putstring(facebook.token, facebook.getaccesstoken()); params.putstring("method", "photos.upload"); asyncfacebookrunner masyncrunner = new asyncfacebookrunner(facebook); masyncrunner.request(null, params, "post", new sampleuploadlistener(), null); public class sampleuploadlistener extends basekeylistener implements requestlistener { public void oncomplete(final string response, final object state) { try { // process response here: (executed in background thread) log.d("facebook-example", "response: " + response.tostring()); jsonobject json = util.parsejson(response); final string src = json.getstring("src"); // post processed result ui thread // if not this, runtime exception generated // e.g. "calledfromwrongthreadexception: original // thread created view hierarchy can touch views." } catch (jsonexception e) { log.w("facebook-example", "json error in response"); } catch (facebookerror e) { log.w("facebook-example", "facebook error: " + e.getmessage()); } } public void onfacebookerror(facebookerror e, object state) { // todo auto-generated method stub } public bitmap getinputtype(bitmap img) { // todo auto-generated method stub return img; } public int getinputtype() { // todo auto-generated method stub return 0; } public void onioexception(ioexception e, object state) { // todo auto-generated method stub } public void onfilenotfoundexception(filenotfoundexception e, object state) { // todo auto-generated method stub } public void onmalformedurlexception(malformedurlexception e, object state) { // todo auto-generated method stub } }
Comments
Post a Comment