Android:相机打开但不保存拍摄,为什么?

时间:2016-11-08 10:19:41

标签: android

我正在尝试拍照并将其保存在Gallary应用中。到目前为止,我设法编写了以下代码:

public void sendMessages(View view) {
        Intent intent = new Intent(this, MessagingAdapter.class);
        startActivity(intent);
    }

    public void takePicture(View view) {
        Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, getImageUri());
        startActivityForResult(cameraIntent, TAKE_PHOTO_CODE);
    }


    public Uri getImageUri() {
        picNo++;

        String storageFolderPath = Environment.getExternalStorageDirectory() + "/CameraImages/";
        String fullFileName = storageFolderPath + picNo + ".jpg";
        File newPic = new File(fullFileName);

        Uri outputFileUri = Uri.fromFile(newPic);
        return outputFileUri;
    }

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == 1)
            return;
        if (requestCode == 3) {
            Uri uri = data.getData();  //YOU GET DATA HERE
        }
    }

它正常工作且没有错误。但是,它不能按我的意愿运作。

我正在测试Nexus-7(CynongeMode)。我的应用程序可以打开相机。但是在拍摄之后,它会在拍摄的图像上冻结并提供3个选项(相机应用程序是内置应用程序):

  1. 取消并从相机返回我的应用程序,或
  2. 重新拍摄,或
  3. 接受拍摄的照片!
  4. 现在,前两个选项可以正常工作但是第三个选项根本没有做任何事情,它只是冻结如下所示:

    enter image description here

    可能是什么问题以及为什么我可以保存图像?!

    更新

    我提出了一个非常简单的onActivityResult方法。但它甚至没有(调试时)。但是,当我删除cameraIntent.putExtra行时,它会转到onActivityResult但是再次没有保存的图像!!。

1 个答案:

答案 0 :(得分:1)

您是否已将权限放入private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if(comboBox1.Text=="Suma") { decimal s = 0; decimal temp; for (int i = 0; i < numericUpDown1.Value; i++) { var currentNumUpDown = this.panel1.Controls["numericUpDown" + (100 + i).ToString()] as NumericUpDown; var currentNumUpDown2 = this.panel1.Controls["numericUpDown" + (200 + i).ToString()] as NumericUpDown; temp = currentNumUpDown.Value * currentNumUpDown2.Value; s = s + temp; } richTextBox1.Text = s.ToString(); Fin = s; } if (comboBox1.Text == "Produs") { decimal p = 1; decimal temp; for (int i = 0; i < numericUpDown1.Value; i++) { var currentNumUpDown = this.panel1.Controls["numericUpDown" + (100 + i).ToString()] as NumericUpDown; var currentNumUpDown2 = this.panel1.Controls["numericUpDown" + (200 + i).ToString()] as NumericUpDown; temp = currentNumUpDown.Value * currentNumUpDown2.Value; p = p * temp; } richTextBox1.Text = p.ToString(); Fin = p; } if (comboBox1.Text == "Minim") { decimal minim = 2; decimal temp; for (int i = 0; i < numericUpDown1.Value; i++) { var currentNumUpDown = this.panel1.Controls["numericUpDown" + (100 + i).ToString()] as NumericUpDown; var currentNumUpDown2 = this.panel1.Controls["numericUpDown" + (200 + i).ToString()] as NumericUpDown; temp = currentNumUpDown.Value * currentNumUpDown2.Value; if (minim > temp) minim = temp; } richTextBox1.Text = minim.ToString(); Fin = minim; } if (comboBox1.Text == "Maxim") { decimal maxim = -2; decimal temp; for (int i = 0; i < numericUpDown1.Value; i++) { var currentNumUpDown = this.panel1.Controls["numericUpDown" + (100 + i).ToString()] as NumericUpDown; var currentNumUpDown2 = this.panel1.Controls["numericUpDown" + (200 + i).ToString()] as NumericUpDown; temp = currentNumUpDown.Value * currentNumUpDown2.Value; if (maxim < temp) maxim = temp; } richTextBox1.Text = maxim.ToString(); Fin = maxim; } }

Manifest.xml