获取并共享页面URL - webView android

时间:2015-04-23 09:34:27

标签: android

我想获取我的webView中当前页面的网址,分享。 以下是获取页面URL和共享包名称的代码;我不知道如何一起使用它们。

获取网页网址

String url = webView.getUrl();
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
        android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setText(url);
    } else {
        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        android.content.ClipData clip = android.content.ClipData
                .newPlainText("text label", url);
        clipboard.setPrimaryClip(clip);
    }

分享包名称

findViewById(R.id.exitdlg).setVisibility(View.GONE);
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT,
            "http://play.google.com/store/apps/details?id="
                    + "com.air.blahblah");
    startActivity(Intent.createChooser(shareIntent, "Share..."));

我是Android的新手,任何帮助都将受到高度赞赏。

1 个答案:

答案 0 :(得分:1)

您正在使用以下代码获取网址:

String url = webView.getUrl();

因此,在共享意图中使用相同的URL,如下所示:

findViewById(R.id.exitdlg).setVisibility(View.GONE);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT,url); // your above url
startActivity(Intent.createChooser(shareIntent, "Share..."));

希望我回答你的问题。