App crashes after taking a pic
Need Help with this. Looked at many post but can't figure it out. Could
someone please help me.
Error - [ResultInfo{who=null, request=2, result=-1, data=Intent {
act=inline-data dat=content://media/external/images/media/26698 (has
extras) }}]
public int GET_CAM_IMG=2;
public int GET_GAL_IMG=1;
img1.setOnClickListener(new OnClickListener() {
public void onClick(View v){
CharSequence[] names = { "From Gallery", "From Camera" };
new AlertDialog.Builder(context)
.setTitle("Select an option for updating your Profile Picture")
.setItems(names, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int pos) {
// TODO Auto-generated method stub
if (pos == 0) {
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, GET_GAL_IMG);
} else {
Intent i = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
/**
i.putExtra("crop", "true");
i.putExtra("aspectX", 0);
i.putExtra("aspectY", 0);
i.putExtra("outputX", 200);
i.putExtra("outputY", 150);**/
startActivityForResult(i, GET_CAM_IMG);
}}}
)
.setNegativeButton(android.R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
}).create().show();
}
});}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent
intent) {
super.onActivityResult(requestCode, resultCode, intent);
switch (requestCode) {
case 2://Camera
Log.d("take","pic");
if (resultCode == -1) {
Uri selectimage=intent.getData();
Log.d("take","pic");
img1.setImageURI(selectimage);
}
break;
case 3://Selecting from Gallery
Log.d("view","pic");
if (resultCode == -1) {
Bitmap bmp_image = null;
Bundle extras = intent.getExtras();
bmp_image = (Bitmap) extras.get("data");
img1.setImageBitmap(bmp_image);
}
break;
}
}
No comments:
Post a Comment