共享当前加载的webview URL

时间:2017-02-16 14:22:57

标签: android webview

如何获取和共享已在webview中加载的当前网址?我已经拥有共享但它共享主URL。

以下是我的分享代码:

    @Override
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.menu, menu);
    MenuItem shareItem = menu.findItem(R.id.action_share);
    ShareActionProvider mShare = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem);
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, webView.getUrl());
    mShare.setShareIntent(shareIntent);
    shareIntent.putExtra(Intent.EXTRA_STREAM, webView.getUrl());
    mShare.setShareIntent(shareIntent);
    return super.onCreateOptionsMenu(menu);

}

1 个答案:

答案 0 :(得分:0)

使用以下代码设置WebViewClient

    private Sting mTrackUrlChange; //url for sharing
    private WebViewClient webViewClient = new WebViewClient() {
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        // Loading started for URL
    }
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        // Redirecting to URL
    }
    @Override
    public void onPageFinished(WebView view, String url) {
        // Loading finished for URL
    mTrackUrlChange = url;
    }
    };

现在将其设置为代码:webView.setWebViewClient(webViewClient);

声明一个类成员,并从url

为此成员分配onPageFinished的值