public static Uri takePhoto(Context context, final String fileName, File path){
Intent intent = null;
Uri uri= null;
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
String state = Environment.getExternalStorageState();
if (state.equals(Environment.MEDIA_MOUNTED)) {
file = new File(path,fileName);
if(file.exists()){
file.delete();
}
try {
path.mkdirs();
}catch (Exception e){
Utils.showToast(context,"创建路径异常");
Utils.isLogError("FilePath","创建路径异常:"+Log.getStackTraceString(e),isLog);
}
if (currentapiVersion < 24) {
ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.Images.Media.TITLE,fileName);
uri = context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
intent.putExtra(MediaStore.EXTRA_OUTPUT,uri);
}else {
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
uri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT,uri);
}
((Activity) context).startActivityForResult(intent,CAMERA_REQUEST_CODE);
}else{
Utils.showToast(context,"SD卡未挂载");
}
return uri;
}
这是日志:
Unable to create new file: /storage/sdcard0/DCIM/Camera/1509245804437.jpg
android.os.Parcel.readException(Parcel.java:1433)
android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
android.content.ContentProviderProxy.insert(ContentProviderNative.java:420)
android.content.ContentResolver.insert(ContentResolver.java:936)
com.sdj.wallet.util.Utils.takePhone(Utils.java:1727)
com.sdj.wallet.activity.AuthenticatioIdentityCardPicActivity.onClick(AuthenticatioIdentityCardPicActivity.java:402)