Skip to content Skip to sidebar Skip to footer

Using The Camera Intent To Take A Picture Without An Sdcard

I'm having trouble using the camera when there's no sdcard present. When there is an sdcard, using the camera is trivial, e.g. http://www.vogella.com/articles/AndroidCamera/articl

Solution 1:

Try this. It works..

  private Uri imageUri;

  public void onClick(View arg0) {
    switch (arg0.getId()) {     
      case R.id.btnImageCapture:

    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    File dir = context.getDir("directory", Context.MODE_PRIVATE);
    File photo = new File(dir,  "Pic.jpg");
    intent.putExtra(MediaStore.EXTRA_OUTPUT,
            Uri.fromFile(photo));
    imageUri = Uri.fromFile(photo);
    startActivityForResult(intent, OPEN_CAMERA);
                    break;
    }
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case OPEN_CAMERA:
        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();

            }
        }
    }
}

Post a Comment for "Using The Camera Intent To Take A Picture Without An Sdcard"