【发布时间】:2015-06-30 01:20:36
【问题描述】:
我想使用ACTION_SEND 共享图像或视频文件。所以基本上当用户点击图像并选择“共享图像/视频”时,它应该发送选择的图像或选择的视频。
这是我正在使用的代码:
if (filep != null) {
}
File sending=new File(filep);
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_SEND);
intent.setDataAndType(Uri.fromFile(sending),getMimeType(sending.getAbsolutePath()));
intent.putExtra(Intent.EXTRA_STREAM, sending);
startActivity(Intent.createChooser(intent , "Share"));
}
private String getMimeType(String url)
{
String parts[]=url.split("\\.");
String extension=parts[parts.length-1];
String type = null;
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
}
return type;
因此,在测试时,我需要使用哪个应用程序来与WhatsApp,Facebook,电子邮件等共享,然后选择任何一个应用程序,然后说“共享失败,请重试”。我似乎无法弄清楚为什么它不起作用。但是,我有相同的代码来使用ACTION_VIEW 全屏显示图像或视频文件,这似乎很好用,但不适用于共享。
有人可以帮忙吗?
【问题讨论】:
标签: android image video bitmap