/**
*
* @return
*/
public static Intent getPhotoPickIntent() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
intent.setType("image/*");
return intent;
}
/** 检查SD卡状态 **/
public static boolean isSdCardAvailable() {
String externalStorageState = Environment.getExternalStorageState();
if (externalStorageState != null) {
return externalStorageState.equals(Environment.MEDIA_MOUNTED);
}
return false;
}
private static final File PHOTO_DIR = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera");
/**
* from camera
* 给一个file 拍完之后 照片就在file里了
* @param f
* @return
*/
public static Intent getTakePickIntent(File f) {
Uri uri = Uri.fromFile(f);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE, null);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
return intent;
}
public static String getImageUrlFromActivityResult(Activity context, Intent data) {
// 需要从content provider中获取真正的图片路径
String imgPath = null;
Uri photoUri = data.getData();
String[] proj = { MediaStore.Images.Media.DATA };
Cursor actualimagecursor = context.managedQuery(photoUri, proj, null, null, null);
if (actualimagecursor == null || actualimagecursor.getCount() == 0) {
// 如果数据库查不到就判断是不是file schema的,通过file schema可以直接得到文件路径
boolean bFindPath = false;
if (photoUri.getScheme().equals("file")) {
imgPath = photoUri.getPath();
File file = new File(imgPath);
if (null != file && file.exists()) {
bFindPath = true;
}
}
if (!bFindPath) {
return null;
}
} else {
int actualIndex = actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
actualimagecursor.moveToFirst();
imgPath = actualimagecursor.getString(actualIndex);
if (TextUtils.isEmpty(imgPath) || !new File(imgPath).exists()) {
// Toast.makeText(this, R.string.file_invalid,
// Toast.LENGTH_SHORT).show();
return null;
}
}
return imgPath;
}