共享内容在Facebook的Andr​​oid内容、Facebook、oid、Andr

2023-09-13 00:02:56 作者:一个人挺好

我使用意图和Action.SEND分享我的自定义消息像WhatsApp的,Twitter,Facebook和GMail的社交网络。一切都确定在Gmail等应用程序,除了Facebook的!如何定制我的code分享一些在Facebook上呢?我在Facebook上分享使用Facebook的SDK,没有问题,但我想用一个意图去做。

这是我使用的:

 意图sendIntent =新意图();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT,knowTitle +读经MomsApp在http://meadjohnsonasia.com.my/mobileapp完整的文章EnfaMama A +);

sendIntent.putExtra(Intent.EXTRA_SUBJECT,我刚刚看了+ knowTitle);
sendIntent.setType(* / *);
startActivity(Intent.createChooser(sendIntent,分享您最喜爱条));
 

解决方案

我所做的其实是拦截intenthandlers的选择的目标,你可以通过使用你的actionprovider。比方说,你创建了一个项目,有一个onclick启动意图。为了做到这一点,你可以实例化一个actionprovider这样做。这actionprovider可以有一个setOnShareTargetSelectedListener拦截要处理的不同(或根本不^^)的任何意图。请参见下面的$ C $下如何配置你的actionprovider。

  actionProvider.setShareIntent(createShareIntent());
    actionProvider.setOnShareTargetSelectedListener(新OnShareTargetSelectedListener(){

        @覆盖
        公共布尔onShareTargetSelected(ShareActionProvider源,
                意向意图){
            如果(com.facebook.katana.equals(intent.getComponent()getPackageName())及。&安培; mfacebooksharer!= NULL){
                mfacebooksharer.shareStatus(主题,正文);
                  返回true;
                }
                返回false;
        }

    });
 

每当Facebook的选择,我用我的mfacebooksharer来处理这个意图,并按照Facebook的API。 Ofcourse,即actionrpovider需要有一个意图。 (就像你想与意图工作)。我用下面的方法来创建的意图。

 私人意图createShareIntent(){
        intentsetter.setIntentleave(真正的);
        意图shareIntent =新的意图(Intent.ACTION_SEND);
        shareIntent.setType(text / plain的);
        shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,学科);
        shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,文本);
        返回shareIntent;
    }
 

I use intent and Action.SEND for sharing my custom message on social networks like WhatsApp , twitter, Facebook and GMail. Everything is ok on Gmail and other applications except Facebook! How can I customize my code to share something on Facebook as well? I do share on Facebook using Facebook SDK with no problem, but I want to do it using an intent.

this is what I use:

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, knowTitle+"Read the full article via MomsApp by EnfaMama A+ at http://meadjohnsonasia.com.my/mobileapp");

sendIntent.putExtra(Intent.EXTRA_SUBJECT, "I just read "+knowTitle);
sendIntent.setType("*/*");
startActivity(Intent.createChooser(sendIntent, "Share Your Favorite Article"));

解决方案

What I did was actually to intercept the chosen target of the intenthandlers, you can do that by using your actionprovider. Let's say you created an item that with an onclick starts the intent. In order to do that, you can instantiate an actionprovider to do so. This actionprovider can have a setOnShareTargetSelectedListener to intercept any intents that you want to handle differently (or not at all ^^). See the code below for how to configure your actionprovider.

 actionProvider.setShareIntent(createShareIntent());
    actionProvider.setOnShareTargetSelectedListener(new OnShareTargetSelectedListener(){

        @Override
        public boolean onShareTargetSelected(ShareActionProvider source,
                Intent intent) {
            if ("com.facebook.katana".equals(intent.getComponent().getPackageName()) && mfacebooksharer != null) {
                mfacebooksharer.shareStatus(subject, text);
                  return true;
                }
                return false;
        }

    });

Whenever facebook is chosen, I use my mfacebooksharer to handle the intent and follow the facebook API. Ofcourse, that actionrpovider needs to have an intent. (Just like you wanted to work with an intent). I use the method below to create the intent.

 private Intent createShareIntent() {
        intentsetter.setIntentleave(true);
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
        shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, text);          
        return shareIntent;
    }