How do you turn off share history when using ShareActionProvider?

后端 未结 8 687
遇见更好的自我
遇见更好的自我 2020-12-02 23:31

The new ShareActionProvider available in Android 4.0 (or in earlier versions if you\'re using ActionBarSherlock) has a feature where the last used item is displayed in the a

8条回答
  •  旧时难觅i
    2020-12-02 23:47

    I created my own version of the ShareActionProvider (and supporting classes), you can copy them into your project (https://gist.github.com/saulpower/10557956). This not only adds the ability to turn off history, but also to filter the apps you would like to share with (if you know the package name).

    private final String[] INTENT_FILTER = new String[] {
            "com.twitter.android",
            "com.facebook.katana"
    };
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.journal_entry_menu, menu);
    
        // Set up ShareActionProvider's default share intent
        MenuItem shareItem = menu.findItem(R.id.action_share);
    
        if (shareItem instanceof SupportMenuItem) {
            mShareActionProvider = new ShareActionProvider(this);
            mShareActionProvider.setShareIntent(ShareUtils.share(mJournalEntry));
            mShareActionProvider.setIntentFilter(Arrays.asList(INTENT_FILTER));
            mShareActionProvider.setShowHistory(false);
            ((SupportMenuItem) shareItem).setSupportActionProvider(mShareActionProvider);
        }
    
        return super.onCreateOptionsMenu(menu);
    }
    

提交回复
热议问题