bug:如标题
思路:
captureModule的setUpCameraOutputs调用MediaSaveService的ImageSaveTask,然后调用storage的insertImage返回一个uri,把uri传给MediaSaveService的onMediaSave,由于这个uri为空所以 点 不进去
修改storage的insertImage
private static Uri insertImage(ContentResolver resolver, ContentValues values, String path, Context context) {
Uri uri = null;
try {
//uri = resolver.insert(Images.Media.EXTERNAL_CONTENT_URI, values);
if (sSaveSDCard) {
Set<String> a=MediaStore.getExternalVolumeNames(context);
String sdcardName=null;
for (String s:a){
if(!s.equals("external_primary")){
sdcardName=s;
}
}
Uri inserUri = Images.Media.getContentUri(sdcardName);
uri = resolver.insert(inserUri, values);
if(uri==null) {
String[] projection = {
"_id", "_data", "_display_name"
};
Cursor c = resolver.query(inserUri, projection, null, null, "_id DESC", null);
if (c != null) {
Log.w(TAG, "c.number" + c.getCount());
if (c.moveToFirst()) {
int _id = c.getInt(0);
uri = Uri.parse(inserUri.toString()+"/"+_id);
}
}
c.close();
}
} else {
uri = resolver.insert(Images.Media.EXTERNAL_CONTENT_URI, values);
}
} catch (Throwable th) {
// This can happen when the external volume is already mounted, but
// MediaScanner has not notify MediaProvider to add that volume.
// The picture is still safe and MediaScanner will find it and
// insert it into MediaProvider. The only problem is that the user
// cannot click the thumbnail to review the picture.
Log.e(TAG, "Failed to write MediaStore" + th);
}
return uri;
}
在插入之后要通知媒体库更新
if (Storage.isSaveSDCard()) { String path1 = Storage.generateFilepath(title, pictureFormat); Uri uri1 = Uri.fromFile(new File(path1)); Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri1); sendBroadcast(intent); // return uri1; }
video也是这个思路修改