If I use an Intent with ACTION_SEND and type "text/plain" and a EXTRA_TEXT Facebook doesn't prefill anything. That's something I've already seen. Every one says, use the Facebook SDK but I don't want my app to post anything automatically nor handle login tokens from my app. I just want the Write Post Facebook screen to be opened with a pre defined text, link and an Image. Just like when I share an image from the Gallery app. Is it possible?
Asked
Active
Viewed 1,680 times
2
-
its an know bug in the facebook .. may you can design the dialog like facebook and can post it with one touch. – itsrajesh4uguys Mar 14 '13 at 13:42
-
but how does the Gallery app deal with this issue? If I chose Facebook to share a photo, the photo appears in the Facebook app. – Héctor Júdez Sapena Mar 14 '13 at 13:55
-
That done by via Intent.ACTIONSEND intent – itsrajesh4uguys Mar 14 '13 at 14:03
-
http://stackoverflow.com/questions/5214764/how-to-share-photo-with-caption-via-android-share-intent-on-facebook – itsrajesh4uguys Mar 14 '13 at 14:05
-
ok, so it is possible to send an image but not a text? – Héctor Júdez Sapena Mar 14 '13 at 14:10
-
yeah... but you can do it both by using facebook api. – itsrajesh4uguys Mar 14 '13 at 14:39
-
http://stackoverflow.com/questions/3515198/share-text-on-facebook-from-android-app-via-action-send have a look at this . they told we can – itsrajesh4uguys Mar 14 '13 at 14:42
-
from this you will come know how to use facebook sdk http://stackoverflow.com/questions/11504129/share-text-and-image-together-using-facebook-sdk-in-android – itsrajesh4uguys Mar 14 '13 at 14:43
-
yes, with the Facebook SDK you can post anything but it is done automatically. The user doesn't have a chance of writing something in the post unless you use the ugly Feed Dialog (https://developers.facebook.com/docs/howtos/androidsdk/3.0/feed-dialog/). And this solution also forces me to create an app in the Facebook developers console, link it to my app... deal with login, etc etc... – Héctor Júdez Sapena Mar 14 '13 at 14:51
-
let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/26165/discussion-between-itsrajesh4uguys-and-hector-judez-sapena) – itsrajesh4uguys Mar 14 '13 at 15:00
1 Answers
2
Ok, it is impossible to do it via Intent. The only solution to show text, images + links and let the user write something before it is posted is by using the ugly Feed Dialog (or creating an custom activity with an EditText in which the user can write someting).
Here's the code that works:
public class FacebookPostActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_facebook_post);
Session.openActiveSession(this, false, new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
if(session.isOpened()){
publishFeedDialog();
}
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
private void publishFeedDialog() {
Bundle params = new Bundle();
params.putString("name", "Facebook SDK for Android");
params.putString("caption", "Build great social apps and get more installs.");
params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
params.putString("link", "https://developers.facebook.com/android");
params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
WebDialog feedDialog = new WebDialog.FeedDialogBuilder(this, Session.getActiveSession(), params)
.setOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(Bundle values, FacebookException error) {
if(error == null){
final String postId = values.getString("post_id");
if(postId != null){
Toast.makeText(FacebookPostActivity.this, "Posted story, id: " + postId, Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(FacebookPostActivity.this, "Publish cancelled", Toast.LENGTH_SHORT).show();
}
}else if(error instanceof FacebookOperationCanceledException){
// User clicked the "x" button
Toast.makeText(FacebookPostActivity.this, "Publish cancelled", Toast.LENGTH_SHORT).show();
}else{
// Generic, ex: network error
Toast.makeText(FacebookPostActivity.this, "Error posting story", Toast.LENGTH_SHORT).show();
}
}
}).build();
feedDialog.show();
}
}

Héctor Júdez Sapena
- 5,329
- 3
- 23
- 31