Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nexus Camera-- Never returns data

Tags:

android

In the app I am allowing the user to change their avatar picture to one of their choosing. The picture (once cropped) is then stored in the private context of the app. I have had great success with what I am doing, however, on the Nexus the camera never returns the data so that the method can move forward. It just sits and waits until you have to manually force shut down the app. It is working on other 4.0 ICS devices, however, not on the Nexus.. The Nexus is allowing the user to pick from their gallery and it works just fine, just not when taking a new picture. Is there a trick to getting this to work???

Here is a segment of the code:

Once again please note that this is working on other devices without a problem:

final String [] items = new String [] {"Take from camera", "Select from gallery"};
ArrayAdapter adapter = new ArrayAdapter (this, android.R.layout.select_dialog_item,items); AlertDialog.Builder builder = new AlertDialog.Builder(this);

    builder.setTitle("Select Image");
    builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
        public void onClick( DialogInterface dialog, int item ) { //take picture
            if (item == 0) {
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                try {
                    intent.putExtra("return-data", true);
                    startActivityForResult(intent, PICK_FROM_CAMERA);
                } catch (ActivityNotFoundException e) {
                    e.printStackTrace();
                }
            } else { //pick from file
                Intent intent = new Intent();

                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);

                startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_FILE);
            }
        }
    });

    final AlertDialog dialog = builder.create();
    mImageView = (ImageView) findViewById(R.id.me_photo);
    File file = new File(context.getCacheDir(), "Avatar"+".png");
    if (file.exists()) {


        //Log.i("CACHE_test", file.getPath());

        Bitmap bitmap = BitmapFactory.decodeFile(file.getPath());

        mImageView.setImageBitmap(bitmap);
    }

    mImageView.setOnClickListener(new View.OnClickListener(){
        public void onClick(View arg0) {
            dialog.show();
        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK) return;
    switch (requestCode) {
        case PICK_FROM_CAMERA:
            mImageCaptureUri= data.getData();
            doCrop();
            break;
        case PICK_FROM_FILE: 
            mImageCaptureUri = data.getData();
            doCrop();
            break;          
        case CROP_FROM_CAMERA:          
            Bundle extras = data.getExtras();
            if (extras != null) {               
                Bitmap photo =(Bitmap) data.getExtras().get("data");
                        //extras.getParcelable("data");
                mImageView.setImageBitmap(photo);
               // FileOutputStream fos = null;
                File file = new File(context.getCacheDir(), "Avatar"+".png");


                    try {
                        file.createNewFile();
                        FileOutputStream fos = new FileOutputStream(file);

                        photo.compress(Bitmap.CompressFormat.PNG, 95, fos);
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        Toast.makeText(this, "Sorry, Camera Crashed-Please Report as Crash A.", Toast.LENGTH_LONG).show();
                    } 
            }

            break;
    }
}

1 Answers

This is a common issue, some models of devices uses different extra key attributes,

so command as
Bitmap photo =(Bitmap) data.getExtras().get("data");

could point to null elements or small thumbnail elements

Take a look to this article

like image 74
Silverstorm Avatar answered Jan 29 '26 03:01

Silverstorm