80,351
社区成员
发帖
与我相关
我的任务
分享
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAG"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<permission android:name="android.permission.WRITE_MEDIA_STORAGE" />
private boolean saveToLocal(){
boolean result = false;
String fileName = MD5Converter.getMD5(currentImage) + ".jpg";
String path = Environment.getExternalStorageDirectory() + "/savedImage/";
//String path = Environment.getExternalStorageDirectory() + "/";
File folder = new File(path);
if (!folder.exists()) {
boolean b = folder.mkdirs();
Toast.makeText(getApplicationContext(), b+"", 1).show();
}
File file = new File(path + fileName);
Toast.makeText(getApplicationContext(), file.getAbsolutePath(), 1).show();
if (!file.exists()) {
try {
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
file.createNewFile();
// BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
// bitmap.compress(Bitmap.CompressFormat.JPEG, 80, bos);
// bos.flush();
// bos.close();
// Toast.makeText(getApplicationContext(), "Saved!", 1).show();
Toast.makeText(getApplicationContext(), file.getPath(), 1).show();
}else{
Toast.makeText(getApplicationContext(), "SD card error", 1).show();
}
//update gallery
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri uri = Uri.fromFile(file);
intent.setData(uri);
this.sendBroadcast(intent);
} catch (IOException e) {
e.printStackTrace();
}
}
return result;
}