我想在WebView中接受用戶的任何頁面,並允許他們與FaceBook/etc共享URL作爲ACTION_SEND意圖。將URL從WebView傳遞給ShareActionProvider?
我試過這個,但顯然URL不存在於onCreateOptionsMenu。我如何將它移動到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;
}
只是一個說明,我的意思是將它傳遞給onOptionsItemSelected,以便「url」將有一個值(頁面加載後) – wilxjcherokee