简体   繁体   English

Nexus Camera-从不返回数据

[英]Nexus Camera— Never returns data

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. 我已经取得了很大的成功,但是,在Nexus上,相机永远不会返回数据,因此该方法可以继续前进。 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. 它正在开发其他4.0 ICS设备,但不在Nexus上.Nexus允许用户从他们的画廊中选择并且它工作正常,只是在拍摄新照片时。 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"}; final String [] items = new String [] {“Take from camera”,“Select from gallery”};
ArrayAdapter adapter = new ArrayAdapter (this, android.R.layout.select_dialog_item,items); ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.select_dialog_item,items); AlertDialog.Builder builder = new AlertDialog.Builder(this); 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;
    }
}

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 可以指向null元素或小缩略图元素

Take a look to this article 看看这篇文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM