共享失败,请重试(仅在whatsapp中) [英] sharing failed, please try again (only in whatsapp)
本文介绍了共享失败,请重试(仅在whatsapp中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我与whatsapp共享内容时,它返回到共享页面,并带有吐司通知共享失败,请重试"
when i am sharing content to whatsapp,it returns back to share page with toast notification "Sharing failed, Please try again"
我的代码
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;
和我的logcat
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
推荐答案
存在相同的问题-解决方案是定义MIME类型:尝试与文本共享意图并且附加图像设置sharingIntent.setType("*/*")
可以正常工作时,但是在如上所述仅共享文本时会失败.
Had the same problem - solution was in defining the MIME type: when trying to share an intent with text and an attached image setting sharingIntent.setType("*/*")
would work fine, but would fail when sharing only text as described above.
解决方案:如果仅共享文本集sharingIntent.setType("text/plain")
Solution: if sharing ONLY text set sharingIntent.setType("text/plain")
public void sendShareToWhatsAppIntent() {
//setup intent:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
//setup image extra, if exists:
Bitmap picBitmap = getMyBitmap();
if (picBitmap != null) {
String url = MediaStore.Images.Media.insertImage(context.getContentResolver(), picBitmap, "", "");
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
sharingIntent.setType("*/*");
} else {
//if no picture, just text set - this MIME
sharingIntent.setType("text/plain");
}
//setup sharing message
String message = "My Message - hey whatsapp!"
sharingIntent.putExtra(Intent.EXTRA_TEXT, message.toString());
//target WhatsApp:
sharingIntent.setPackage("com.whatsapp");
if (sharingIntent.resolveActivity(context.getPackageManager()) != null) {
startActivity(sharingIntent);
} else {
Log.w(TAG, "sendShareIntent: cant resolve intent");
Toast.makeText(context, "whatsapp not installed", Toast.LENGTH_SHORT).show();
}
}
这篇关于共享失败,请重试(仅在whatsapp中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文