对话从画廊或从相机挑选图像 [英] Dialog to pick image from gallery or from camera
问题描述
有没有调用与对话框一种标准的方式选择要么从相机选择一个图片或从库得到(如在内置的电话簿或Skype的)?
Is there a standard way to call dialog box with choose either to pick an image from the camera or to get from gallery (like in build-in phone book or Skype)?
我已经采取了看看这但是code打开库不表明从相机挑吧。
I've taken a look at this but the code opens gallery without suggesting to pick it from camera.
设备:三星Galaxy Tab
安卓2.3.3
Device: Samsung Galaxy Tab
Android: 2.3.3
推荐答案
低于code可用于拍摄和挑选照片并选择任挑照片或拍摄的照片只显示一个对话框,有两个选择,一旦选择使用适当的code ...
below code can be use for taking and picking photo and for selection of either pick photo or take photo just show a dialog with two option and upon selection use the appropriate code ...
从相机拍摄照片。
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePicture, 0);//zero can be replaced with any action code
挑照片从画廊
to pick photo from gallery
Intent pickPhoto = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(pickPhoto , 1);//one can be replaced with any action code
onactivity结果code ::
onactivity result code::
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case 0:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
imageview.setImageURI(selectedImage);
}
break;
case 1:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
imageview.setImageURI(selectedImage);
}
break;
}
}
终于在manifest文件中添加此权限
finally add this permission in the manifest file
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
这篇关于对话从画廊或从相机挑选图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!