Using Android action bar share intent

雨燕双飞 提交于 2019-12-01 00:58:47

If you want a static share Intent (i.e., it never changes), then you update your onCreateOptionsMenu to be

public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.mainpage, menu);
    MenuItem item = menu.findItem(R.id.menu_item_share);
    mShareActionProvider = (ShareActionProvider) item.getActionProvider();
    // Create the share Intent
    String playStoreLink = "https://play.google.com/store/apps/details?id=" +
        getPackageName();
    String yourShareText = "Install this app " + playStoreLink;
    Intent shareIntent = ShareCompat.IntentBuilder.from(this)
        .setType("text/plain").setText(yourShareText).getIntent();
    // Set the share Intent
    mShareActionProvider.setShareIntent(shareIntent);
    return true;
}

you can get the official tutorial here http://developer.android.com/guide/topics/ui/actionbar.html#ActionProvider

In the snappet you paste, you forget to call

mShareActionProvider.setShareIntent(intent);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!