我想在我的 WebView 中获取用户用户所在的任何页面,并允许他们与 FaceBook/etc 共享 URL 作为 ACTION_SEND 意图。
我试过了,但显然 onCreateOptionsMenu 中不存在 URL。如何将其移至 onOptionsItemsSelected?
private ShareActionProvider mShareActionProvider;
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
return super.onOptionsItemSelected(item);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
MenuItem item = menu.findItem(R.id.menu_item_share);
mShareActionProvider = (ShareActionProvider)item.getActionProvider();
mShareActionProvider.setShareHistoryFileName(
ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
mShareActionProvider.setShareIntent(createShareIntent());
return true;
}
private Intent createShareIntent() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT,
web.getUrl());
return shareIntent;
}