图片存储

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本地图片压缩+转base64
  6. Android(安卓)图片左上角、右上角标签tag
  7. Android(安卓)使用decodeFile方法加载手机磁盘中的图片文件
  8. android 生成圆角和带倒影图片
  9. google地图demo

随机推荐

  1. Android(安卓)使用SoundPool播放音频
  2. Android Studio保存log到本地
  3. Android实现图表绘制和展示
  4. Android开发框架SmartAndroid2.0 强劲框
  5. android ListView用法简介
  6. Android(安卓)四大组件 简介
  7. Android设计模式系列(1)--SDK源码之组合
  8. Android数字签名
  9. 懒骨头的Android文档备份1:建造你的第一个
  10. Android(安卓)Mediacodec硬解H264并显示