图片存储

if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{

if(image != null)
{
String sdardDir = Environment.getExternalStorageDirectory().toString();
String name = sdardDir+"/appname/images/"+imagename+".jpg";
java.io.File file = new java.io.File(sdardDir+"/appname/images");
boolean bool = true;
if(!file.isDirectory())
{
bool = file.mkdirs() ;
}

if(bool)

{

File iamgeFile = new File(path);
if(!iamgeFile.exists())
{
try {iamgeFile.createNewFile();} catch (IOException e1) {e1.printStackTrace();error= "1"+e1.toString(); }
}
FileOutputStream fOut = null;
try { fOut = new FileOutputStream(iamgeFile); } catch (FileNotFoundException e) { e.printStackTrace();
error= "2"+e.toString(); }
image.compress(Bitmap.CompressFormat.JPEG, 100, fOut); // png格式图片 image.compress(Bitmap.CompressFormat.png, 100, fOut);
try { fOut.flush(); } catch (IOException e) { e.printStackTrace();
error="3"+ e.toString(); }
try { fOut.close();} catch (IOException e) { e.printStackTrace();
error= "4"+e.toString(); }

}

}

else{

Toast t = Toast.makeText(this, "无sdcard", Toast.LENGTH_SHORT);
t.show();

}



媒体库更新

- 通过 Intent.ACTION_MEDIA_MOUNTED 进行全扫描
public void allScan(){
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"
+ Environment.getExternalStorageDirectory())));
}

- 通过 Intent.ACTION_MEDIA_SCANNER_SCAN_FILE 扫描某个文件
public void fileScan(String fName){
Uri data = Uri.parse("file:///"+fName);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, data));
}



详细http://wenku.baidu.com/view/537b9b8ecc22bcd126ff0c97.html

http://devbbs.doit.com.cn/viewthread.php?tid=31528

更多相关文章

  1. android 单击 切换图片 --- 注意图片大小
  2. android设置一个图片为全屏大小
  3. Android(安卓)调用系统相机拍照的返回结果
  4. Android遍历某个文件夹的图片并实现滑动查看的的Gallery
  5. android sdcard文件存储 + 媒体库更新方法
  6. Android(安卓)显示大图片
  7. Android(安卓)图片左上角、右上角标签tag
  8. Android(安卓)使用decodeFile方法加载手机磁盘中的图片文件
  9. android 生成圆角和带倒影图片

随机推荐

  1. android 中的日历控件
  2. android 无root截屏
  3. Android(安卓)Studio 2.0 to Android(安
  4. #Android(安卓)Ticks#Mount a filesystem
  5. Android: Sensors on Android(安卓)2.3 -
  6. android下拉弹出框
  7. Android(安卓)android:persistentDrawing
  8. ch011 Android(安卓)Galley与ImageSwitch
  9. android屏幕分辨率适配
  10. Android(安卓)ListView