android把图片 视频 保存到相册
//android把图片文件添加到相册
ContentResolver localContentResolver = getContentResolver(); ContentValues localContentValues = getImageContentValues(MonitorActivity.this, file, System.currentTimeMillis()); localContentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, localContentValues); Intent localIntent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE"); final Uri localUri = Uri.fromFile(fileshare); localIntent.setData(localUri); sendBroadcast(localIntent);
public static ContentValues getImageContentValues(Context paramContext, File paramFile, long paramLong)
{
ContentValues localContentValues = new ContentValues();
localContentValues.put("title", paramFile.getName());
localContentValues.put("_display_name", paramFile.getName());
localContentValues.put("mime_type", "image/jpeg");
localContentValues.put("datetaken", Long.valueOf(paramLong));
localContentValues.put("date_modified", Long.valueOf(paramLong));
localContentValues.put("date_added", Long.valueOf(paramLong));
localContentValues.put("orientation", Integer.valueOf(0));
localContentValues.put("_data", paramFile.getAbsolutePath());
localContentValues.put("_size", Long.valueOf(paramFile.length()));
return localContentValues;
}
android把视频文件添加到相册
//是否添加到相册 ContentResolver localContentResolver = this.getContentResolver(); ContentValues localContentValues = getVideoContentValues(this, file, System.currentTimeMillis()); Uri localUri = localContentResolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, localContentValues);
public static ContentValues getVideoContentValues(Context paramContext, File paramFile, long paramLong)
{
ContentValues localContentValues = new ContentValues();
localContentValues.put("title", paramFile.getName());
localContentValues.put("_display_name", paramFile.getName());
localContentValues.put("mime_type", "video/3gp");
localContentValues.put("datetaken", Long.valueOf(paramLong));
localContentValues.put("date_modified", Long.valueOf(paramLong));
localContentValues.put("date_added", Long.valueOf(paramLong));
localContentValues.put("_data", paramFile.getAbsolutePath());
localContentValues.put("_size", Long.valueOf(paramFile.length()));
return localContentValues;
}