调用相机和手机内部图片

来源:互联网 发布:米 网络用语 编辑:程序博客网 时间:2024/04/27 21:15
private void dialog() {AlertDialog.Builder builder = new Builder(mContext);builder.setTitle("上传照片");builder.setItems(new String[] { "拍照上传", "本地上传" },new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int which) {dialog.dismiss();Intent intent = null;switch (which) {case 0://调用相机意图intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);File dir = new File("/sdcard/mengfaceForAndroid/Camera/");if (!dir.exists()) {dir.mkdirs();}mApplication.mImagePath = "/sdcard/mengfaceForAndroid/Camera/"+ UUID.randomUUID().toString();File file = new File(mApplication.mImagePath);if (!file.exists()) {try {file.createNewFile();} catch (IOException e) {}}//解析器Uri用于存储请求的图像或视频。intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(file));startActivityForResult(intent, 0);break;case 1://ACTION_PICK 返回的数据结果中选择一个intent = new Intent(Intent.ACTION_PICK, null);//EXTERNAL_CONTENT_URI 从URI获取所以图片数据intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,"image/*");startActivityForResult(intent, 1);break;}}});builder.create().show();}

0 0
原创粉丝点击