2

I want to intercept the user selecting the share intent and if they select facebook to launch the facebook sdk.

I am confused by the API documentation which is contradicting. 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

but if you look at the listener 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.

One says you can intercept one says you can't intercept. Looks like you can't by playing with the return value on the listener but I was wondering if anyone had a workaround or fix for this.

user1634451
  • 5,133
  • 6
  • 30
  • 43

1 Answers1

0

See the code below for how to configure your 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;
    }

Source: Sharing Content On FaceBook Android

Community
  • 1
  • 1
Andrea Motto
  • 1,540
  • 21
  • 38
  • 1
    you can't modify the intent read what I posted in the question. My work around for this was to extend the class – user1634451 Feb 20 '15 at 05:49
  • You posted: "I want to intercept the user selecting the share intent ... Looks like you can't by playing with the return value on the listener" and I posted the solution. If you look for something else just edit your question. – Andrea Motto Feb 21 '15 at 03:07
  • 1
    From what I understand of the documentation, you just get notified that the share action has been called so you can do things.. this what they mean intercept, but you can not do any modifications to the intent such as add extras or change the target of the intent like if you want to change the shared file or image.. – Moti Bartov Jul 28 '15 at 20:00