<pre name="code" class="java"> String path = file.getAbsolutePath();
ContentResolver cr = mContext.getContentResolver();
StringBuffer buff = new StringBuffer();
buff.append("(")
.append(Images.ImageColumns.DATA)
.append("=")
.append("'" + path + "'")
.append(")");
Cursor cur = cr.query(
Images.Media.EXTERNAL_CONTENT_URI,
new String[] { Images.ImageColumns._ID },
buff.toString(), null, null);
int index = 0;
//match the index to parse the uri
for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) {
index = cur.getColumnIndex(Images.ImageColumns._ID);
index = cur.getInt(index);
}
if (index != 0) {
uri = Uri.parse("content://media/external/images/media/"+ index);
}
//protection.
if(uri == null)
{
uri = Uri.fromFile((File)file.getContent());
}
uriList.add(uri);
if (MULTIPART_TYPE.equals(mimeType))
continue;
String singleType = FileHelper.getSharedMIMEType(file);
if (mimeType == null) {
mimeType = singleType;
} else if (singleType.equals(mimeType))
continue;
else {
mimeType = MULTIPART_TYPE;
}
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList);
intent.setType(</span>"image/*"<span style="white-space:pre">);
mContext.startActivity(Intent.createChooser(intent, mContext.getText(R.string.sharing)));
android分享多张图片在ContentResolver.insert返回null时的解决方案
最新推荐文章于 2021-01-17 10:37:19 发布