2

我想拦截选择共享意图的用户,如果他们选择 facebook 来启动 facebook sdk。

我对自相矛盾的 API 文档感到困惑。 http://developer.android.com/reference/android/widget/ShareActionProvider.html

public void setOnShareTargetSelectedListener (ShareActionProvider.OnShareTargetSelectedListener listener)

Added in API level 14
Sets a listener to be notified when a share target has been selected. The listener can optionally decide to handle the selection and not rely on the default behavior which is to launch the activity

但是如果你看一下监听 器 http://developer.android.com/reference/android/widget/ShareActionProvider.OnShareTargetSelectedListener.html

public abstract boolean onShareTargetSelected (ShareActionProvider source, Intent intent)

Added in API level 14
Called when a share target has been selected. The client can decide whether to perform some action before the sharing is actually performed.

Note: Modifying the intent is not permitted and any changes to the latter will be ignored.

Note: You should not handle the intent here. This callback aims to notify the client that a sharing is being performed, so the client can update the UI if necessary.

一个说你可以拦截一个说你不能拦截。看起来你不能在监听器上玩返回值,但我想知道是否有人有解决方法或解决这个问题。

4

1 回答 1

0

有关如何配置 ShareActionProvider 的信息,请参阅下面的代码:

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;
        }
    });

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;
    }

来源:在 Facebook Android 上共享内容

于 2015-02-19T23:27:52.140 回答