0

I have an Android WebView app and i have added share action in it, which shares URL of the current page of the webview. but i want it to send text content of the page instead of URL. please help me with share intent. following is my code for share intent.

case R.id.menu_item_share: {
                Intent shareIntent = new Intent(Intent.ACTION_SEND);
                shareIntent.setType("text/plain");
                shareIntent.putExtra(Intent.EXTRA_TEXT, myWebView.getUrl());
                startActivity(Intent.createChooser(shareIntent, "Share This Website!"));
                shareIntent.setPackage("com.whatsapp");

                break; //or, return true;
sagar chaudhary
  • 33
  • 1
  • 12

1 Answers1

0

If you need to get the content of the web page, please try it like this.

URL url = new URL("http://www.google.com/");
URLConnection con = url.openConnection();
Pattern p = Pattern.compile("text/html;\\s+charset=([^\\s]+)\\s*");
Matcher m = p.matcher(con.getContentType());

String charset = m.matches() ? m.group(1) : "ISO-8859-1";
Reader r = new InputStreamReader(con.getInputStream(), charset);
StringBuilder buf = new StringBuilder();
while (true) {
   int ch = r.read();
   if (ch < 0)
   break;
  buf.append((char) ch);
}
String str = buf.toString();
Sergey
  • 65
  • 1
  • 7