【问题标题】:Camera Intent - Storage full相机意图 - 存储已满
【发布时间】:2015-07-29 10:13:13
【问题描述】:

当我按下photoButton 时,默认的相机应用程序会启动。

我的问题是它说存储已满。 当我单独启动相机应用程序时,错误没有出现。

这是相机意图的代码:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
        case CAMERA_PIC_REQUEST: {
            try {
                Bitmap image = (Bitmap) data.getExtras().get("data");
                ImageView imageView = (ImageView) findViewById(R.id.taskPhotoImage);
                imageView.setImageBitmap(image);

            } catch (NullPointerException e) {
                e.printStackTrace();
            }
        }
        case REQ_CODE_SPEECH_INPUT: {
            if (resultCode == RESULT_OK && null != data) {
                ArrayList<String> result = data
                        .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
                textField.setText(textField.getText() + " " + result.get(0));
            }
            break;
        }
    }
}

在 onCreate() 方法中:

photoButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);

        }
    });

我不知道这是否是代码中的问题。不过好像出了点问题

亲切的问候

【问题讨论】:

    标签: android android-intent camera


    【解决方案1】:

    试试这个:-

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    
        // After camera screen this code will excuted
    
        if (requestCode == CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE) {
    
            if (resultCode == RESULT_OK) {
    
                output.setText("Video File : " +data.getData());
    
                // Video captured and saved to fileUri specified in the Intent
                Toast.makeText(this, "Video saved to:" + data.getData(), Toast.LENGTH_LONG).show();
    
            } else if (resultCode == RESULT_CANCELED) {
    
                output.setText("User cancelled the video capture.");
    
                // User cancelled the video capture
                Toast.makeText(this, "User cancelled the video capture.", 
                        Toast.LENGTH_LONG).show();
    
            } else {
    
                output.setText("Video capture failed.");
    
                // Video capture failed, advise user
                Toast.makeText(this, "Video capture failed.", 
                        Toast.LENGTH_LONG).show();
            }
        }
    }
    

    【讨论】:

      【解决方案2】:

      试试这个

       @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      switch (requestCode) {
      case TAKE_PICTURE:
          if (resultCode == Activity.RESULT_OK) {
              Uri selectedImage = imageUri;
              getContentResolver().notifyChange(selectedImage, null);
              ImageView imageView = (ImageView) findViewById(R.id.ImageView);
              ContentResolver cr = getContentResolver();
              Bitmap bitmap;
              try {
                   bitmap = android.provider.MediaStore.Images.Media
                   .getBitmap(cr, selectedImage);
      
                  imageView.setImageBitmap(bitmap);
                  Toast.makeText(this, selectedImage.toString(),
                          Toast.LENGTH_LONG).show();
              } catch (Exception e) {
                  Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT)
                          .show();
                  Log.e("Camera", e.toString());
              }
          }
      }}
      

      如果你想要相机意图

          private static final int TAKE_PICTURE = 1;    
      private Uri imageUri;
      
      public void takePhoto(View view) {
      Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
      File photo = new File(Environment.getExternalStorageDirectory(),  "picture.jpg");
      intent.putExtra(MediaStore.EXTRA_OUTPUT,
              Uri.fromFile(photo));
      imageUri = Uri.fromFile(photo);
      startActivityForResult(intent, TAKE_PICTURE);
      }
      

      【讨论】:

        猜你喜欢
        • 2013-10-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-09
        • 2011-12-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多