给系统库添加文件后扫描更新系统图库
paintPath = MediaStore.Images.Media.insertImage(context.getContentResolver(),bitmap,str,null);
Uri uri = Uri.parse(paintPath);
/**
* 通过uri获得文件路径
* @param context
* @param uri
* @return
*/
public static String getFilePathByContentResolver(Context context, Uri uri) {
if (null == uri) {
return null;
}
Cursor c = context.getContentResolver().query(uri, null, null, null, null);
String filePath = null;
if (null == c) {
throw new IllegalArgumentException(
"Query on " + uri + " returns null result.");
}
try {
if ((c.getCount() != 1) || !c.moveToFirst()) {
} else {
filePath = c.getString(
c.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA));
}
} finally {
c.close();
}
return filePath;
}
// Tell the media scanner about the new file so that it is // immediately available to the user. MediaScannerConnection.scanFile(this, new String[] { file.toString() }, null, new MediaScannerConnection.OnScanCompletedListener() { public void onScanCompleted(String path, Uri uri) { Log.i("ExternalStorage", "Scanned " + path + ":"); Log.i("ExternalStorage", "-> uri=" + uri); } });

浙公网安备 33010602011771号