任何人都可以分享代码(或向我指出 Android 示例代码)来帮助我将图像添加到媒体商店(图库)中的相册中。
在我的应用程序中,我从服务器下载图像,并使用相机(通过 Intent)拍摄新图像。
我想将这些图像组织在特定于应用程序的相册中,类似于 Facebook(和其他应用程序)应用程序的做法,使相关图像整齐地组织起来。
我不久前按照 Media Store API 文档对此进行了研究,但它对我不起作用......所以需要一些帮助。
Thanks
这是一种用于将图像存储在公共图片文件夹中的方法,其中包含自定义应用程序文件夹。
public void saveImageToExternal(String imgName, Bitmap bm) throws IOException {
//Create Path to save Image
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES+appFolder); //Creates app specific folder
path.mkdirs();
File imageFile = new File(path, imgName+".png"); // Imagename.png
FileOutputStream out = new FileOutputStream(imageFile);
try{
bm.compress(Bitmap.CompressFormat.PNG, 100, out); // Compress Image
out.flush();
out.close();
// Tell the media scanner about the new file so that it is
// immediately available to the user.
MediaScannerConnection.scanFile(context,new String[] { imageFile.getAbsolutePath() }, null,new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
} catch(Exception e) {
throw new IOException();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)