1

Link to solution/workaround at bottom of question

I used the Android tutorial to write code to open the nexus 7 camera via intents and take a photo. It refused to work properly unless I altered the file object initialisation code from

File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), "MyCameraApp");

to

File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES) + File.separator +"MyCameraApp");

and even then intent.getData() is still null when onActivityResult is called. Back to the question at hand though: I can see the saved image browsing on the tablet itself, but not when I browse it on the PC via USB.

What am I doing wrong? I thought using getExternalStoragePublicDirectory made files completely accessible. Could there be something else wrong with my code? Do I need to somehow "tell" the stock camera app to save it as MODE_WORLD_READABLE or something along those lines?

Spent hours and hours trying to get this working properly - any help would be appreciated!

I can post the rest of my code if it would help - its almost identical to the Android tutorial though.

EDIT: This is caused by a known problem with the nexus 7 and 4. See 2nd link for solution

Saving files on external storage on Nexus 7 and retrieving from PC

Nexus 4 not showing files via MTP

Community
  • 1
  • 1
nme32
  • 213
  • 2
  • 15

1 Answers1

0

I do something similar like this:

File photo = new File(Environment.getExternalStorageDirectory(),
                "filename.jpg");
        mImageUri = Uri.fromFile(photo);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE)
                .putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
        startActivityForResult(intent, REQUEST_CODE_TAKE_PHOTO);

And after take and save photo call from terminal (or cmd):

adb pull /mnt/storage/sdcard/filename.jpg c:\folder

and get result photo from c:\folder. You can use Log or debugger to monitoring mImageUri address on your device.

PS: And dont forget permissions about permissions

ADK
  • 513
  • 3
  • 8
  • 22
  • Hmmmm..... it'd be nice to have a solution which didn't require the end users having to do all this - they'd have to install the adb on their PC right? Should have made clear the app will be intended for non technical users I guess. (I did set permissions as per the tutorial) When you say using eclipse to monitor mImageUri address did you mean so that I can then find the file via windows explorer? – nme32 Apr 17 '13 at 12:08
  • I have just demonstrate that you can access picture from the device, and filename.jpg have to appear on the device storage, so you can give it via windows explorer or smth like that. Another question if you cannot find the storage of that file, so eclipse or another IDE (i use IDEA for instance) debugger could help to find it (just monitor mImageUri variable). – ADK Apr 17 '13 at 12:19
  • 1
    I can find the saved images using the `adb shell` in `/sdcard/Pictures/MyCameraApp`, but in windows explorer `Nexus 7\Internal storage\Pictures\MyCameraApp` is empty. And only `Nexus 7` is visible at the root level of the mounted device (via USB). If I could just get the pictures to save to `Internal storage` somehow.... I think this might be a problem particular to the Nexus 7 as it has no sd card slot. – nme32 Apr 17 '13 at 12:36
  • hmmm, really strange. Could you try to get photo via adb pull? – ADK Apr 17 '13 at 12:39
  • I tried `adb pull IMG_20130417_103644.jpg 'C:\Documents and Settings\xxx\My Documents'` after navigating to the image folder and it returns `error: device not found` . Did I make a syntax error there? There must be some way to tell android to save the file to the storage folder that will be mounted when connected to a PC but I can't find anything on it. – nme32 Apr 17 '13 at 12:59
  • Do you monitor mImageUri (in my example mImageUri, you have another Uri var name i suggest) ? Also you can use Dalvik Debug Monitor (ANDROID_SDK_DIR/tools/ddms.bat) then Device->File Explorer -> /storage/sdcard...or smth like that it depends on you Uri. Than find your IMG_20130417_103644.jpg in folder and click on left top icon (diskette like). All of this the same as adb pull /mnt/storage/sdcard/IMG_20130417_103644.jpg C:\Documents and Settings\xxx\My Documents (By the way you should not write quotes around C:\Documents and Settings\xxx\My Documents) – ADK Apr 17 '13 at 13:22
  • Thanks, using the DDMS worked for me. In my code `fileUri` is `file:///storage/emulated/0/Pictures/MyCameraApp/IMG_20130417_143711.jpg` Looking around in the DDMS browser this is the only `storage/emulated/0/` is the only path I can find with `Pictures` etc in it. – nme32 Apr 17 '13 at 13:38
  • If I browse the filesystem on the device itself I find the `Pictures Movies Music` etc structure mirrored on `mnt` `storage` and `sdcard` folders and more at the root level, and my pictures are in all these DIRS. I am using File Expert browser - apparently it can see folders other browser can't. Since my pictures are in all of the mirrored directories this makes me think it is a permissions issue. – nme32 Apr 17 '13 at 13:52
  • I think you can change the dir) For example instead of Environment.getExternalStoragePublicDirectory() use another custom File with it own Uri...but it is just suggestion OR! Maybe you should to use getExternalStorageDirectory() instead of getExternalStoragePublicDirectory()? – ADK Apr 17 '13 at 14:13
  • Not sure what you mean by your last comment. `getExternalStorageDirectory()` I did try - it has the same problem. I guess I could type in a path for the Uri manually but I wouldn't know which folder to save in in order for images to appear when mounted on a windows PC. There are 5 folders in which `Pictures Movies Music` etc appear and the images appear in all of them anyway. Truly flummoxed. Thanks for your help though. – nme32 Apr 17 '13 at 14:32