whatsapp分享whatsapp:// send?text = content_here

时间:2015-08-23 21:28:06

标签: android

我使用下面的代码来分享我的Android应用程序中的内容,该应用程序将webview页面显示给whatsapp。

除了一个问题外,它的工作正常。 它共享完整的链接,包括whatsapp:// send?text = 我只希望共享内容。

  Uri uri = Uri.parse(url);
 Intent sendIntent = new Intent();
  sendIntent.setAction(Intent.ACTION_SEND);
 sendIntent.putExtra(Intent.EXTRA_TEXT, ""  + uri);
 sendIntent.setType("text/plain");
 sendIntent.setPackage("com.whatsapp");
 startActivity(sendIntent);

我尝试使用replace来替换whatsapp:// send?文本但是它给出了错误,即替换(字符串,字符串)是未定义的。

有没有更好的方法来实现这个

1 个答案:

答案 0 :(得分:0)

好的,所以,你需要通过char去一个char,直到你到达char"?"。创建一个循环并逐个字符地去。当你到达"?"离开循环,并选择字符串的其余部分作为新字符串。 What is the easiest/best/most correct way to iterate through the characters of a string in Java?

在那之后,你的strin来自charAt("?"是+ 1)到最后。