3

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

这是我用于启动相机活动并将数据传递给onActivityResult()

不知道怎么回事奇怪请帮帮我

提前感谢

 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;

            }
        }
    }
4

0 回答 0