Вопрос по android – Как отключить историю обмена при использовании ShareActionProvider?

25

Error: User Rate Limit Exceeded

Ваш Ответ

8   ответов
1

yourShareActionProvider.setShareHistoryFileName(null);

Sets the file name of a file for persisting the share history which history will be used for ordering share targets. This file will be used for all view created by onCreateActionView(). Defaults to DEFAULT_SHARE_HISTORY_FILE_NAME. Set to null if share history should not be persisted between sessions.

Error: User Rate Limit Exceeded Quentamia
Error: User Rate Limit Exceededjava.lang.IllegalStateException: No preceding call to #readHistoricalData.
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded Quentamia
Error: User Rate Limit Exceeded
0

chooserView.getDataModel().setHistoryMaxSize(0);

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v7.internal.widget.ActivityChooserView;
import android.support.v7.widget.ShareActionProvider;
import android.view.View;


public class MyShareActionProvider extends ShareActionProvider {
    /**
     * Creates a new instance.
     *
     * @param context Context for accessing resources.
     */
    public MyShareActionProvider(Context context) {
        super(context);
    }

    @Override
    public View onCreateActionView() {
        ActivityChooserView chooserView = (ActivityChooserView) super.onCreateActionView();
        Drawable icon;
        if (Build.VERSION.SDK_INT >= 21) {
            icon = getContext().getDrawable(R.drawable.share_icon);
        }else{
            icon = getContext().getResources().getDrawable(R.drawable.share_icon);
        }
        chooserView.setExpandActivityOverflowButtonDrawable(icon);
        chooserView.getDataModel().setHistoryMaxSize(0);
        return chooserView;
    }

}
3

ShareActionProvider

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceededstackoverflow.com/a/17290249/1446466Error: User Rate Limit Exceeded
-1

    private void addShareSelectedListener() {
    if (null == mShareActionProvider) return;
    OnShareTargetSelectedListener listener = new OnShareTargetSelectedListener() {
        public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
            mContex.startActivity(intent);
            return true;
        }
    };

//Set to null if share history should not be persisted between sessions.
    mShareActionProvider.setShareHistoryFileName(null);
    mShareActionProvider.setOnShareTargetSelectedListener(listener);

}
21

 <item 
    android:id="@+id/menu_action_share"
    android:showAsAction="ifRoom" 
    android:icon="@drawable/ic_action_share"
    android:title="@string/share"/>   

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_actions, menu);
    return super.onCreateOptionsMenu(menu);
 }

private void actionShare(){
     Intent i = new Intent(Intent.ACTION_SEND);
     i.setType("text/plain");
     i.putExtra(Intent.EXTRA_SUBJECT, "my string");
     i.putExtra(Intent.EXTRA_TEXT, "another string");
     startActivity(i); 
     //Or like above will always display the chooser
     //startActivity(Intent.createChooser(i, getResources().getText(R.string.share))); 
 }

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.menu_item_share:
            actionShare();
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }

Error: User Rate Limit Exceeded
Error: User Rate Limit ExceededisError: User Rate Limit ExceededShareActionProviderError: User Rate Limit ExceededallError: User Rate Limit Exceeded
-1
    getSupportMenuInflater().inflate(R.menu.share_action_provider, menu);

    // Set file with share history to the provider and set the share intent.
    MenuItem actionItem = menu.findItem(R.id.menu_item_share_action_provider_action_bar);
    ShareActionProvider actionProvider = (ShareActionProvider) actionItem.getActionProvider();
    ***actionProvider.setShareHistoryFileName(null);
    OnShareTargetSelectedListener listener = new OnShareTargetSelectedListener() {
        public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
            startActivity(intent);
            return true;
        }
    };
    actionProvider.setOnShareTargetSelectedListener(listener);***
4

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

shareActionProvider.setShareIntent(intent);
shareActionProvider.setOnShareTargetSelectedListener(this);

@Override
public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
    // start activity ourself to prevent search history
    context.startActivity(intent);
    return true;
}

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceededjava.lang.IllegalStateException: No preceding call to #readHistoricalDataError: User Rate Limit ExceededonShareTargetSelectedError: User Rate Limit Exceeded
Error: User Rate Limit Exceeded

Похожие вопросы