概述
//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;
}
转载于:https://www.cnblogs.com/wikiki/p/5302204.html
最后
以上就是如意犀牛为你收集整理的android把图片 视频 保存到相册的全部内容,希望文章能够帮你解决android把图片 视频 保存到相册所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复