【发布时间】:2016-08-01 09:17:02
【问题描述】:
当我将内容分享到 whatsapp 时,它会返回分享页面并显示 toast 通知“分享失败,请重试”
我的代码
if (url.startsWith("share://")) {
Uri requestUrl = Uri.parse(url);
String pContent = requestUrl.toString().split("share://")[1];
Toast toast=Toast.makeText(getApplicationContext(),pContent, Toast.LENGTH_LONG);
toast.setMargin(50,50);
toast.show();
StringBuilder sb = new StringBuilder();
String [] parts = pContent.split("<br />");
for (int i = 0; i < parts.length; i++) {
String part = parts[i];
sb.append(part);
sb.append('\n');
}
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
share.putExtra(android.content.Intent.EXTRA_TEXT, (Serializable) sb);
share.setType("*/*");
try {
startActivity(Intent.createChooser(share, "Share On"));
} catch (android.content.ActivityNotFoundException ex) {
toast = Toast.makeText(getApplicationContext(), "whatsapp not installed", Toast.LENGTH_LONG);
toast.setMargin(50,50);
toast.show();
}
return true;
还有我的日志猫
08-01 14:37:42.081 1472-1514/com.example.myactivity I/MaliEGL: [Mali]window_type=1, is_framebuffer=0, errnum = 0
08-01 14:37:42.081 1472-1514/com.example.myactivity I/MaliEGL: [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1
08-01 14:37:42.081 1472-1514/com.example.myactivity I/MaliEGL: [Mali]max_allowed_dequeued_buffers=3
【问题讨论】:
-
whatsapp 除外,它适用于环聊、邮件、徒步旅行、文本等其他应用程序,我的编译 sdk 和目标 sdk 是 23,我正在物理设备 android one 中进行测试
-
嗨,Harry,到目前为止有什么解决方案吗?
-
嗨@RishabhBhatia 我得到了解决方案,它对我有用,只需点击此链接stackoverflow.com/a/38697846/5753575
-
就我而言,我使用了错误的示例代码 intent.setType("plain/text");相反 intent.setType("text/plain"); [另见] (faq.whatsapp.com/en/android/28000012)
标签: android android-intent webview