Osm*_*man 5 twitter parameters android
我正在创建一个Android应用程序,其中我想添加Twitter分享按钮,点击Twitter按钮将在Twitter上分享一些东西(标题+网址).我快到了,但我的链接有问题.当我用"&"给出两个参数时,它将不起作用.如果有人有合适的答案,请告诉我.答案将非常感谢.
//Full URL: http://www.mywebsite.com/index.php?option=com_content&catid=40&id=12546&view=article**
String title = "Hello title";
String catid = "40";
String id = "12546";
Uri.Builder b = Uri.parse("http://www.mywebsite.com/").buildUpon();
b.path("index.php");
b.appendQueryParameter("option=com_content&catid", catid);
b.appendQueryParameter("&id", id);
b.appendQueryParameter("&view=article", null);
b.build();
String url = b.build().toString();
String tweetUrl = "https://twitter.com/intent/tweet?text=" + title + "&url=" + url;
Uri uri = Uri.parse(tweetUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
Run Code Online (Sandbox Code Playgroud)
输出:=>"http://www.mywebsite.com/index.php?option=com_content&catid=40"
但缺少=>"&id = 12546&view = article".
您不应在“appendQueryParameter”的第一个参数内提供与号 (&),它将自动为您添加。将其用作:
b.appendQueryParameter("id", id); // instead of ("*&*id", id);
b.appendQueryParameter("view=article", null); // instead of ("*&*view=article", null);
Run Code Online (Sandbox Code Playgroud)
输出将是您期望的输出
https://twitter.com/intent/tweet?text=Hello title&url=http://www.mywebsite.com/index.php?option%3Dcom_content%26catid=40&id=12546&view%3Darticle=null
Run Code Online (Sandbox Code Playgroud)
请参阅此处的用法示例。