使用意图捕获图片后,应用程序崩溃

ven*_*wda 13 android

使用intents.log cat捕获5到6张照片后,我的应用程序崩溃了.我无法找到崩溃的原因.请帮帮我.

    private void capturePhoto() {

        File root = new File(Environment.getExternalStorageDirectory(), "Feedback");
        if (!root.exists()) {
            root.mkdirs();
        }
        File file = new File(root, Constants.PROFILE_IMAGE_NAME + ".jpeg");
        Uri outputFileUri = Uri.fromFile(file);


        Intent photoPickerIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        photoPickerIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        photoPickerIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
        photoPickerIntent.putExtra("return-data", true);
        photoPickerIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);
        startActivityForResult(photoPickerIntent, requestCode);


    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (this.requestCode == requestCode && resultCode == RESULT_OK) {

            File root = new File(Environment.getExternalStorageDirectory(), "Feedback");
            if (!root.exists()) {
                root.mkdirs();
            }
            File file = new File(root, Constants.PROFILE_IMAGE_NAME+".jpeg");
            checkFlowIdisPresent(file);

            displayPic();


        }
    }
  private void displayPic() {

        String filePath = Environment.getExternalStorageDirectory()
                .getAbsolutePath() + File.separator + "/Feedback/" + Constants.PROFILE_IMAGE_NAME + ".jpeg";
        //  Bitmap bmp = BitmapFactory.decodeFile(filePath);
        //Bitmap scaled = Bitmap.createScaledBitmap(bmp, 300, 300, true);


        File imgFile = new File(filePath);
        Bitmap bmp = decodeFile(imgFile);

        if (imgFile.exists()) {

            dispProfilePic.setImageBitmap(bmp);
        } else {
            dispProfilePic.setBackgroundResource(R.drawable.user_image);

        }
    }

 private Bitmap decodeFile(File f) {
        try {
            // Decode image size
            BitmapFactory.Options o = new BitmapFactory.Options();
            o.inJustDecodeBounds = true;
            BitmapFactory.decodeStream(new FileInputStream(f), null, o);

            // The new size we want to scale to
            final int REQUIRED_SIZE = 70;

            // Find the correct scale value. It should be the power of 2.
            int scale = 1;
            while (o.outWidth / scale / 2 >= REQUIRED_SIZE &&
                    o.outHeight / scale / 2 >= REQUIRED_SIZE) {
                scale *= 2;
            }

            // Decode with inSampleSize
            BitmapFactory.Options o2 = new BitmapFactory.Options();
            o2.inSampleSize = scale;
            return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
        } catch (FileNotFoundException e) {
        }
        return null;
    }
Run Code Online (Sandbox Code Playgroud)

以上代码用于捕获照片并在ImageView中显示捕获的图片.我正在使用MI选项卡.

编辑实际应用程序没有崩溃...它变成白色屏幕,如果我按任何按钮然后它崩溃和onActivityResult不成功,当它变成白色屏幕

新编辑我可以复制这个.我点击了监视器,点击了Android监视器.然后,当我与app交互时,它显示应用程序的内存利用率.现在在左侧栏我点击终止应用程序图标.现在有趣的是它会破坏当前的活动并转移到之前的活动.之前的活动变成了白屏.

请帮帮我们.

ram*_*ari 3

试试这个代码。我在一些应用程序中使用它:

启动意图方法:

private void launchCamera() {
        Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
    }
Run Code Online (Sandbox Code Playgroud)

捕获结果:

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        try {
            if (requestCode == CAMERA_PIC_REQUEST) {
                if (data != null) {
                    Bundle extras = data.getExtras();
                    if (extras != null) {
                        Bitmap thumbnail = (Bitmap) extras.get("data");
                        if (thumbnail != null)
                            displayPic(thumbnail);
                    }
                }
            }
            } catch (Exception e) {
            e.printStackTrace();
            }
    }
Run Code Online (Sandbox Code Playgroud)