简体   繁体   中英

Using camera with no SD card on Android

I just want to confirm that the camera cannot be used without an SD card on Android?

I fire the MediaStore.ACTION_IMAGE_CAPTURE intent to use the camera and was trying to the get the camera to store the image in the apps data folder

    ContentValues values = new ContentValues();
    values.put(Media.TITLE, "Image");
    values.put(Images.Media.BUCKET_ID, path.hashCode());
    values.put(Images.Media.BUCKET_DISPLAY_NAME, name);

    values.put(Images.Media.MIME_TYPE, "image/png");
    values.put(Media.DESCRIPTION, "Image capture by camera");
    values.put("_data", Constants.imagePath);

    Uri uri = getContentResolver().insert(
            Media.EXTERNAL_CONTENT_URI, values);
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

    startActivityForResult(cameraIntent, PICTURE_ACTIVITY);

I assume the camera can not access the apps data folder

So without a SD card there is no way to use the camera?

There is another way you can perform image capturing, using Camera preview on your surface view.

By using this thing, you can save previous image and take a capture. You can pass your application's cache directory getCacheDir() method of context.

Reference :

1) https://github.com/commonsguy/cw-advandroid/tree/master/Camera/Preview/
2) http://android-er.blogspot.in/2010/12/camera-preview-on-surfaceview.html

Without SD card the Camera app will display:

Please insert an SD card before using the camera.

So no, not possible.

Edit: Checking Camera app source code, the updateStorageHint(int remaining) suggests that it will always display the "No storage" text if there is no SD card (also check the MenuHelper calculatePicturesRemaining() ).

http://developer.android.com/guide/topics/media/camera.html#saving-media suggests that it is possible to save images to locations other than the SD card:

Media files ... should be saved to a device's external storage directory (SD Card)

(My emphasis)

Using internal storage, however, would rapidly deplete what is usually a very limited resource and mean that the files are only portable with the phone and not the removed SD card.

I would suggest that for reliability and in the interests of 'best practice' (a phrase I don't like) you follow the recommendations in that guide.

It seems that the built in camera app adheres to these best practices, but it would be possible to write an app that doesn't.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM