Android:如何通过意图与Facebook上的文本共享图像? [英] Android: How to share image with text on facebook via intent?

查看:114
本文介绍了Android:如何通过意图与Facebook上的文本共享图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



$ b

示例代码

$ b我希望通过Facebook的分享意向与我的应用程序分享一张预先填写的图片的照片。
$ b

  Intent intent = new Intent(); 
intent.setAction(Intent.ACTION_SEND);
intent.setType(image / *);

intent.putExtra(Intent.EXTRA_TEXT,eample);
intent.putExtra(Intent.EXTRA_TITLE,example);
intent.putExtra(Intent.EXTRA_SUBJECT,example);
intent.putExtra(Intent.EXTRA_STREAM,imageUri);

Intent openInChooser = new Intent(intent);
openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS,extraIntents);
startActivity(openInChooser);

这里是屏幕截图我获得了





如果设置类型要图像/ *然后上传照片,而不填充文本。如果设置为文本/普通照片不显示.....

解决方案

最新的Facebook版本不允许您使用意图共享文本。您必须使用Facebook SDK来做到这一点 - 要做到这一点,使用Facebook SDK + Android Simple Facebook( https:/ /github.com/sromku/android-simple-facebook )。使用图书馆,你的代码就像这样(从简单的Facebook网站提取):



发布Feed



设置 OnPublishListener 并呼叫:




  • publish Feed,OnPublishListener)没有对话框。

  • 发布(Feed,true,OnPublishListener) / li>


基本属性




  • 消息 - 用户的消息

  • 名称 - 链接附件的名称

  • caption - 链接的标题(出现在链接名称下方)

  • 描述 - 链接描述(显示在链接标题下方)

  • 图片附加到此信息的图片的URL。该图片必须至少为200px x 200px

  • 链接 - 附加到此信息的链接



初始化回调监听器:

  OnPublishListener onPublishListener = new OnPublishListener() 
@Override
public void onComplete(String postId){
Log.i(TAG,成功发布,新的帖子id =+ postId);


/ *
*您可以在此覆盖其他方法:
* onThinking(),onFail(String reason),onException(Throwable throwable)
* /
};

构建Feed:

 
.setName(Android的简单的Facebook)
。 setCaption(Code less,do ...)
.setDescription(简单的Facebook图书馆项目通过编写较少的代码以便能够登录,发布Feed和打开图形故事,邀请朋友,更多)
.setPicture(https://raw.github.com/sromku/android-simple-facebook/master/Refs/android_facebook_sdk_logo.png)
.setLink(https:/ /github.com/sromku/android-simple-facebook)
.build();

发布Feed 没有对话框:

  mSimpleFacebook.publish(feed,onPublishListener); 

发布Feed 对话框:

  mSimpleFacebook.publish(feed,true,onPublishListener); 




14上更新2015年12月





根据新的Facebook SDK。


facebook-android-sdk:4.6.0


这很简单。


1。在中创建提供者Android.manifest.xml

 < provider 
android:authority =com.facebook.app.FacebookContentProvider {APP_ID}
android:name =com.facebook.FacebookContentProvider
android: exports =true/>

2。创建您的分享意图与数据。


  ShareLinkContent shareLinkContent = new ShareLinkContent.Builder()
.setContentTitle(你的标题)
.setContentDescription(你的描述)
.setContentUrl(Uri.parse(URL [将打开网站或应用程序]))
.setImageUrl (Uri.parse(image or logo [if playstore or app store url then no need of this image url]))
.build();



3。显示共享对话框

  ShareDialog.show(ShowNavigationActivity.this,shareLinkContent); 



就是这样。


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

Example code

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

intent.putExtra(Intent.EXTRA_TEXT, "eample");
intent.putExtra(Intent.EXTRA_TITLE, "example");
intent.putExtra(Intent.EXTRA_SUBJECT, "example");
intent.putExtra(Intent.EXTRA_STREAM, imageUri);

Intent openInChooser = new Intent(intent);
openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
startActivity(openInChooser);

Here is screen shot what I get

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

解决方案

The newest Facebook versions doesn't allow you to share text using intents. You have to use the Facebook SDK to do it - to make that simple, use the Facebook SDK + Android Simple Facebook (https://github.com/sromku/android-simple-facebook). Using the library, your code would be like this (extracted from the Simple Facebook site):

Publish feed

Set OnPublishListener and call for:

  • publish(Feed, OnPublishListener) without dialog.
  • publish(Feed, true, OnPublishListener) with dialog.

Basic properties

  • message - The message of the user
  • name - The name of the link attachment
  • caption - The caption of the link (appears beneath the link name)
  • description - The description of the link (appears beneath the link caption)
  • picture - The URL of a picture attached to this post. The picture must be at least 200px by 200px
  • link - The link attached to this post

Initialize callback listener:

OnPublishListener onPublishListener = new OnPublishListener() {
    @Override
        public void onComplete(String postId) {
            Log.i(TAG, "Published successfully. The new post id = " + postId);
        }

     /* 
      * You can override other methods here: 
      * onThinking(), onFail(String reason), onException(Throwable throwable)
      */
};

Build feed:

Feed feed = new Feed.Builder()
    .setMessage("Clone it out...")
    .setName("Simple Facebook for Android")
    .setCaption("Code less, do the same.")
    .setDescription("The Simple Facebook library project makes the life much easier by coding less code for being able to login, publish feeds and open graph stories, invite friends and more.")
    .setPicture("https://raw.github.com/sromku/android-simple-facebook/master/Refs/android_facebook_sdk_logo.png")
    .setLink("https://github.com/sromku/android-simple-facebook")
    .build();

Publish feed without dialog:

mSimpleFacebook.publish(feed, onPublishListener);

Publish feed with dialog:

mSimpleFacebook.publish(feed, true, onPublishListener);


Update on 14 December 2015


according to New Facebook SDK.

facebook-android-sdk:4.6.0

It's very Simple.
1. create Provider in Android.manifest.xml

<provider
            android:authorities="com.facebook.app.FacebookContentProvider{APP_ID}"
            android:name="com.facebook.FacebookContentProvider"
            android:exported="true" />

2. Create Your Share Intent with Data.

ShareLinkContent shareLinkContent = new ShareLinkContent.Builder()
                .setContentTitle("Your Title")
                .setContentDescription("Your Description")
                .setContentUrl(Uri.parse("URL[will open website or app]"))
                .setImageUrl(Uri.parse("image or logo [if playstore or app store url then no need of this image url]"))
                .build();


3. Show The Share Dialog

ShareDialog.show(ShowNavigationActivity.this,shareLinkContent);


That's It.

这篇关于Android:如何通过意图与Facebook上的文本共享图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆