Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
425 views
in Technique[技术] by (71.8m points)

How to share photo with CAPTION via Android share intent on Facebook?

I'd like to share a photo with caption pre-filled from my app via a share intent, on facebook.

I know how to share photo or how to share text, but how do I share them together?

Example code

Intent shareCaptionIntent = new Intent(Intent.ACTION_SEND);
    shareCaptionIntent.setType("image/*");

    //set photo
    shareCaptionIntent.setData(examplePhoto);
    shareCaptionIntent.putExtra(Intent.EXTRA_STREAM, examplePhoto);

    //set caption
    shareCaptionIntent.putExtra(Intent.EXTRA_TEXT, "example caption");
    shareCaptionIntent.putExtra(Intent.EXTRA_SUBJECT, "example caption");

    startActivity(Intent.createChooser(shareCaptionIntent,getString(R.string.share)));

If a set type to image/* then a photo is uploaded without the caption prefilled. If a set it to text/plain only the caption is uploaded without the photo.....


My guess is that the issue is that the Android Facebook App doesn't look for Intent.EXTRA_TEXT when it filters an ACTION_SEND Intent with type image/* for photo uploading. So this issue could be resolved if the Android Facebook App looked for that value, and if present, inserted it as the caption of the image.

Share caption via Android Intent

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Add this line to your existing codes:

shareCaptionIntent.putExtra(Intent.EXTRA_TITLE, "my awesome caption in the EXTRA_TITLE field");

There is no clearly defined differences among EXTRA_TITLE, EXTRA_SUBJECT and EXTRA_TEXT. So there is no clear share protocol. We could always try them all. :-)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...