Paul Robert Carlson
Paul Robert Carlson

Reputation: 169

android camera saving, but not showing up on the sd card

I am working on adding a camera to my application, I have basically decided to go with adding an intent to it, and using the built in camera. The intent works, it calls it just fine, but when it goes to save it gets weird. according to Eclipse the photos are saving to the SD card, I can see them and pull them off when i go under FileExplorer. However, when I actually go to and explore the SD card, the files are not there.

public class C4Main extends Activity {
private static final int REQUEST_CODE = 1;
private Bitmap bitmap;
private ImageView imageView;
private Camera cam;
private SurfaceHolder sh;
private Uri fileUri;

/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Log.d("testing","before intent");
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    fileUri = getOutputMediaFileUri(1); // create a file to save the image
    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
    Log.d("testing","fileUri: "+fileUri);
    // start the image capture Intent
    startActivityForResult(intent, 100);
    Log.d("testing","after startactivity");
}
private static Uri getOutputMediaFileUri(int type){
      return Uri.fromFile(getOutputMediaFile(type));
}

/** Create a File for saving an image or video */
private static File getOutputMediaFile(int type){
    // To be safe, you should check that the SDCard is mounted
    // using Environment.getExternalStorageState() before doing this.

    File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
              Environment.DIRECTORY_PICTURES), "MyCameraApp");
    // This location works best if you want the created images to be shared
    // between applications and persist after your app has been uninstalled.

    // Create the storage directory if it does not exist
    if (! mediaStorageDir.exists()){
        if (! mediaStorageDir.mkdirs()){
            Log.d("MyCameraApp", "failed to create directory");
            return null;
        }
    }

    // Create a media file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    File mediaFile;
    if (type == 1){
        mediaFile = new File(mediaStorageDir.getPath() + File.separator +
        "IMG_"+ timeStamp + ".jpg");
        Log.d("testing loop","Filepath: "+mediaFile.getPath());
    } else if(type == 2) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator +
        "VID_"+ timeStamp + ".mp4");
    } else {
        return null;
    }

    return mediaFile;
}
}

that is the code that I am using, copied from developer.google. And as I said according to FileExplorer in Eclipse it is saving to the designated path, but it just is not on my SD card. My hardware is ASUS Transformer prime running android 4.0.3. Tha manifest is set-up with permission for both external writing and camera use.

Any help would be greatly appreciated.

Upvotes: 1

Views: 1402

Answers (2)

ASP
ASP

Reputation: 1974

I'm using this intent for using built-in camera. It automatically stores the image in SD card.

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
                    flagImage=1;
                    startActivityForResult(cameraIntent, CAMERA_REQUEST); 

Upvotes: 2

Vinit ...
Vinit ...

Reputation: 1459

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
try {
        if (requestCode == CAMERA_REQUEST) {
            Bitmap photo = (Bitmap) data.getExtras().get("data");
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);
                String snapName = getRealPathFromURI(newuri);

                Uri u = Uri.parse(snapName);

                File f = new File("" + u);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
                photo.compress(CompressFormat.PNG, 0 /* ignored for PNG */,
                        bos);
                byte[] bitmapdata = bos.toByteArray();
// Storing Image in new folder
                StoreByteImage(mContext, bitmapdata, 100, fileName);

Upvotes: 0

Related Questions