摄影后为什么相机意图不会返回

时间:2014-01-25 18:33:16

标签: android android-intent camera

我正在尝试编写一个允许用户选择打开相机的功能,然后当用户拍摄一张照片时,它返回,获取缩放的照片并在imageView上设置该位图。问题是市场上的默认相机或其他相机应用程序在拍摄照片后不会触发返回案例,如何解决?感谢

拍照按钮:

takePic.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                File tempFile;
                try {
                    tempFile = File.createTempFile("my_app", ".jpg");
                    fileName = tempFile.getAbsolutePath();
                    Uri uri = Uri.fromFile(tempFile);
                    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
                    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
                        startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
                    }
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }           
        });

意图结果后

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == REQUEST_GET_IMAGE_ALBUM && resultCode == RESULT_OK) {
            Uri selectedImage = data.getData();
            Intent shareIntent = new Intent(this, SharePicForm.class);
            shareIntent.putExtra("photo", Utility.getImagePath(selectedImage,this));
            startActivity(shareIntent);
        } else if ( requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
            Log.d("test1","return");
            Intent shareIntent = new Intent(this, SharePicForm.class);
            shareIntent.putExtra("photo", data.getStringExtra(MediaStore.EXTRA_OUTPUT));
            startActivity(shareIntent);
        }

    }

0 个答案:

没有答案