I have an application that works fully. He just has 1 problem with my camera intent or permissions.
It is assumed that the application triggers a camera action when the user clicks a button. This works fine, but when the user accepts the image by pressing the OK button on the camera, he does not return to my application. If they press the cancel button on the camera, it will return to my application as expected.
I read all the similar questions that I can find here, but none of them fixed my problem. I need to tell the camera exactly where to save the image, because I want to alternate 2 in my application. Here is the code that creates the camera’s intention and runs 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 tried several values for imagePath (this is String), but the camera’s OK button did not work with any of them. These are the paths I 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 is wrong with my code, or tell me what could be a valid path? I prefer if the image is stored in the cache location, because it doesn’t matter that the image continues to exist after the user leaves the application, but I don’t care who has access to the image.
I am testing everything on the 4.1 emulator, compiling with the 4.1 SDK, and my minimum version is API 8 (2.2).
I put the case for intention in onActivityResult() , but I don’t think you guys should see this code because it should not affect the problem.
java android android-camera
cmasupra
source share