【发布时间】:2014-06-25 15:45:44
【问题描述】:
在我的应用上,我需要设置用户图片。 我打开一个对话框,询问是否打开画廊或相机,然后获取结果并在图像视图中设置。 它适用于画廊,但从相机拍照后,它没有在图像视图中设置(logcat 上没有显示) 有人可以帮我吗?
我设置了写入外部存储的权限
public void TakePictureFromGallery(){
Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, ResultIntentLoad);
}
public void TakePictureFromCamera(){
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePicture, 0);
}
@Override
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();
TakePicture.setImageURI(selectedImage); //Non so perchè non mi inserisce poi la foto
Confirm.setTextColor(Color.parseColor("#000000"));
Confirm.setEnabled(true);
}
break;
case 1:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
TakePicture.setImageURI(selectedImage);
Confirm.setTextColor(Color.parseColor("#000000"));
Confirm.setEnabled(true);
}
break;
}
}
public void ShowDialog(){
//Mostro una dialog dove l'utente può scegliere se aprire la galleria o la fotocamera
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle("Security and identification");
builder.setMessage("Some shops can ask you to show an ID when paying with Satispay. We suggest to to choose a an easily identificable photo of you.");
builder.setCancelable(false);
builder.setNeutralButton("Lybrary",new android.content.DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int id){
TakePictureFromGallery(); //Prendo la foto dalla gallery
dialog.dismiss();
}
});
builder.setPositiveButton("Take",new android.content.DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int id){
TakePictureFromCamera(); //Avvio l'intent per la fotocamera
dialog.dismiss();
}
});
builder.show();
}
【问题讨论】:
标签: android android-camera android-gallery