Android ACTION_IMAGE_CAPTURE意图在onActivityResult上返回null

时间:2013-04-26 13:33:18

标签: android image-capture

当我们开始onActivityResult意图为意图获取null时,我们面临将意图数据传递到ACTION_IMAGE_CAPTURE方法的问题

以下是启动相机活动并将数据传递到onActivityResult()

的代码

不知道什么是错的,请帮帮我

感谢adavnce

 public void takePicture()
    {
        File directory = new File(Environment.getExternalStorageDirectory() + "/AML_AttachmentImages" + "/");

        if (!directory.exists())
        {
            directory.mkdir();
        }

        int count = 0;
        if (directory != null)
        {
            File[] files = directory.listFiles();
            if (files != null)
            {
                count = files.length;
            }
        }
        count++;
        String imagePath = "AML_IMAGE_" + count + ".jpg";
        File file = new File(directory, imagePath);
        outputFileUri = Uri.fromFile(file);

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        startActivityForResult(intent, TAKE_PHOTO_CODE);

    }


 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        if (resultCode == RESULT_OK)
        {
            switch (requestCode)
            {
                case TAKE_PHOTO_CODE :
                    outputFileUri=data.getParcelableExtra(MediaStore.EXTRA_OUTPUT);
                    File imageFilePath = new File(outputFileUri.getPath());
                    imagePathUris.add(imageFilePath.getAbsolutePath());
                    Bitmap myBitmap = BitmapFactory.decodeFile(imageFilePath.getAbsolutePath());
                    bitmaps.add(myBitmap);
                    txtAttachmentsCount.setVisibility(View.VISIBLE);
                    txtAttachmentsCount.setText(getResources().getString(R.string.view_attachment_text) + Integer
                            .toString(imagePathUris.size()) + ")");

                    break;
                case REQ_PIC :
                    final ContentResolver cr = getContentResolver();
                    final String[] p1 = new String[]{MediaStore.Images.ImageColumns._ID,
                            MediaStore.Images.ImageColumns.DATE_TAKEN};
                    Cursor c1 = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, p1, null, null, p1[1] + " DESC");
                    if (c1.moveToFirst())
                    {
                        String uristringpic = "content://media/external/images/media/" + c1.getInt(0);
                        Uri newuri = Uri.parse(uristringpic);
                        Log.i("TAG", "newuri   " + newuri);

                    }
                    c1.close();

                    break;

            }
        }
    }

0 个答案:

没有答案