I have an app that's fully working. It just has 1 problem with my Camera Intent or permissions.
The app is supposed to launch the Camera Activity when the user presses a button. That's working fine, but when the user accepts a picture by clicking the OK button on the camera, it doesn't come back to my app. If they press the cancel button on the camera, it comes back to my app as expected.
I have read all the similar questions I can find on here, but none of them have fixed my problem. I need to tell the camera exactly where to save the image because I want to alternate between 2 in my app. Here's the code that creates the Camera Intent and starts it:
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.parse(imagePath));
startActivityForResult(intent, 11);
I have tried multiple values for imagePath
(which is a String), but the camera's OK button has not worked with any of them. These are the paths I've tried:
/mnt/sdcard/<appName>/cameraImages/image1.jpg
from Environment.getExternalStorageDirectory()
/mnt/sdcard/Android/data/<appPkg>/cache/<appName>/cameraImages/image1.jpg
from context.getExternalCacheDir()
/mnt/sdcard/Android/data/<appPkg>/cache/<appName>/cameraImages/image1.jpg
from context.getCacheDir()
I have the following permissions in my manifest file:
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<uses-feature android:name="android.hardware.camera.flash" android:required="false" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Can you guys help me figure out what's wrong with my code, or tell me what a valid path could be? I prefer if the image is stored in a cache location because it's not important for the image to continue existing after the user leaves the application, but I don't really care who has access to the image.
I'm doing all testing on the 4.1 emulator, compiling with the 4.1 SDK, and my minimum version is API 8 (2.2).
I have put a case for the intent in onActivityResult()
, but I don't think you guys need to see that code because it shouldn't be affecting the problem.