意向+分享+ Action_Send_Multiple + Facebook的工作不 [英] Intent + Share + Action_Send_Multiple + Facebook not working
问题描述
我想使用意向sharing.It能够很好地处理单个图像,或当我使用Intent.ACTION_SEND。
I am trying to use Intent for sharing.It works well with single image or when I use Intent.ACTION_SEND.
但是当我使用Intent.ACTION_SEND_MULTIPLE这似乎并不为如我使用低于code在Facebook工作。
But when i use Intent.ACTION_SEND_MULTIPLE It does not seems to work on Facebook for e.g I am using below code.
ArrayList<Uri> files = new ArrayList<Uri>();
File a = new File(FileUtil.getDefaultMediaFolderPath(), "a.jpeg");
File b = new File(FileUtil.getDefaultMediaFolderPath(), "b.jpeg");
files.add(Uri.fromFile(a));
files.add(Uri.fromFile(b));
if (a.exists()) {
if (b.exists()) {
System.out.println("Both present.");
}
}
Intent shareIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
shareIntent.setType("*/*");
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
startActivity(Intent.createChooser(shareIntent,"share via."));
以上code能够很好地处理Gmail和其附加的图片使用Gmail。但与Facebook似乎并不工作,图像不连接。
Above code works well with Gmail and it attaches the pics with Gmail. But with facebook it doesn't seems to work and images are not attached.
我曾尝试不同的组合,但似乎没有任何工作。虽然当我尝试从设备默认的库它运作良好,并重视所有的图像在Facebook的分享多张图片。
I have tried different combination but nothing seems to work. Although when I try to share multiple images from device default gallery it works well and attaches all the images in Facebook.
请帮助我!
推荐答案
在想很多事情最后,我来到了解决方案,在当前版本的Facebook打破了意向接受多张图片,而即将到来的意图。 ACTION_SEND_MULTIPLE。但我感到惊讶,当多个共享正在与默认的画廊在我的设备。 最后,我的朋友的帮助下(不是想邀功从他身上)。我才知道,默认画廊是在URI发送文件通过使用内容提供商这就是为什么他们是工作,所以我已经改变了我的URI列表为Facebook(我已创建自定义共享对话框,这样我就可以截获这些选项是从分享通过对话打开意图选择。)
After trying lots of things Finally I came to solution that In current version Facebook broke Intent for accepting Multiple Images while coming as Intent. ACTION_SEND_MULTIPLE. But I surprised when Multiple sharing is working with default Gallery in my device. Finally with the help of my friend (not wanted to take credit from him). I came to know that Default GAllery is sending files in URI by using Content Provider thats why they are working So I have changed my URI list for Facebook (I have created custom share dialog, So I can intercept which option is selected from Share Dialog opened via Intent.)
private void updateUrisForFacebook() {
if (intent.getAction().equalsIgnoreCase(Intent.ACTION_SEND_MULTIPLE)) {
ArrayList<Uri> uris = intent
.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
for (int i = 0; i < uris.size(); i++) {
Uri uri = uris.get(i);
String path = uri.getPath();
File imageFile = new File(path);
uri = getImageContentUri(imageFile);
uris.set(i, uri);
}
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
}
}
private Uri getImageContentUri(File imageFile) {
String filePath = imageFile.getAbsolutePath();
Cursor cursor = context.getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
new String[] { MediaStore.Images.Media._ID },
MediaStore.Images.Media.DATA + "=? ",
new String[] { filePath }, null);
if (cursor != null && cursor.moveToFirst()) {
int id = cursor.getInt(cursor
.getColumnIndex(MediaStore.MediaColumns._ID));
Uri baseUri = Uri.parse("content://media/external/images/media");
return Uri.withAppendedPath(baseUri, "" + id);
} else {
if (imageFile.exists()) {
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.DATA, filePath);
return context.getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
} else {
return null;
}
}
}
最后,它的工作原理:)
Finally It works :)
所以,基本的想法是你的URI列表转换成内容提供商的URI列表,然后选中它会工作。的
So Basic Idea is to convert your URI list into Content provider URI list and then check it will work.
这篇关于意向+分享+ Action_Send_Multiple + Facebook的工作不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!