Android Image doesn't save using native camera app on Nexus S

倖福魔咒の 提交于 2019-12-12 12:39:31

问题


So this is kind of weird because out of the three devices I'm testing on, I only get this issue on the Google Nexus S with 4.0.3. I'm starting the native camera app to take a picture, and I don't care where the image is saved to, so I don't specify, hoping that it will get saved to the default location, but no location is saved at all!

Does work fine on the Galaxy S 2 and Samsung Skyrocket (both with 2.3.something).

Code I'm using to start the app

Intent camIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(camIntent, TAKE_PHOTO);
return true;

I'm keeping it really simple, that's why I'm confused! Does anyone know of any issues specific to the Nexus S's camera?

EDIT: It would seem that maybe the Nexus S's camera app saves the file in some onActivityResult, and since I start up the native camera app and don't save the image upon return, it doesn't save it. Does anyone know this this to be true? Seen this behavior?

EDIT: No one has seen this? I find it hard to believe I'm the first person to run into this...

EDIT: Alright, well after working on it some more, I tried adding a URI into the EXTRA_OUTPUT of the intent like so:

camIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                            Uri.parse(folderPath + String.format("%d.jpg", System.currentTimeMillis())));

And now I see the behavior described here: Android ACTION_IMAGE_CAPTURE Intent where the camera app doesn't do anything when I hit ok, and creating the file beforehand doesn't work either, as I tried like this:

File f = new File(folderPath, filename);
f.createNewFile();
camIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.parse(folderPath + filename));

回答1:


Alright, figured it out. Oddly, and I have NO idea why, but changing this line:

camIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.parse(folderPath + filename));

to

camIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));

fixed it. Don't know if I should understand why... but whatever, it works. I did try a billion other things...

not specifying an EXTRA_OUTPUT at all -> camera would act like everything was good... except it wouldn't save the image ANYWHERE

getting the bitmap taken by intent.getExtras().get("data") -> did return a bitmap, but it was not the full size image as documented extensively in many bug reports

using the above Uri.parse method -> causes the native camera app checkmark button to not do anything when clicked

Hope this helps someone..



来源:https://stackoverflow.com/questions/10937659/android-image-doesnt-save-using-native-camera-app-on-nexus-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!