Man, I am still not able to save a picture when I send an intent asking for a photo to be taken. Here's what I am doing:
Make a URI representing the pathname
android.content.Context c = getApplicationContext();
String fname = c.getFilesDir().getAbsolutePath()+"/parked.jpg";
java.io.File file = new java.io.File( fname );
Uri fileUri = Uri.fromFile(file);
Create the Intent (don't forget the pkg name!) and start the activity
private static int TAKE_PICTURE = 22;
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
intent.putExtra("com.droidstogo.boom1." + MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult( intent, TAKE_PICTURE );
The camera activity starts, and I can take a picture, and approve it. My onActivityResult()
then gets called. But my file doesn't get written.
The URI is: file:///data/data/com.droidstogo.boom1/files/parked.jpg
I can create thumbnail OK (by not putting the extra into the Intent), and can write that file OK, and later read it back).
Can anyone see what simple mistake I am making? Nothing obvious shows up in the logcat - the camera is clearly taking the picture. Thanks,
Peter
I should mention that I have the appropriate permissions set in the AndroidManifest.xml file:
<uses-permission android:name="android.permission.READ_OWNER_DATA" />
<uses-permission android:name="android.permission.WRITE_OWNER_DATA" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-library android:name="com.google.android.maps" />
</application>
Any ideas? Any ideas on things to try, to get more info about the problem?
This can cause issues like the pictures taken with the camera don't save in Gallery. Though, you can easily fix this by visiting your Android phone's Settings > Apps > Camera and tapping on the “Storage” or “Manage Storage” option. From here, you can just tap on the “Clear Cache” button to get rid of its cache content.
If you get the error message "Failed to save file." and you are unable to save your file, go to the File menu and select [Save As] to save the file in a different location. If you are still unable to save the file, please check your security software settings.
Control-click the illustration that you want to save as a separate image file, and then click Save as Picture. In the Save as type list, select the file format that you want. In the Save As box, type a new name for the picture, or just accept the suggested file name.
From Start> Control Panel (or Start> Settings> Control Panel)> Default Programs> select Windows Photo Viewer> click on Set this program as default. Then, also from Default Programs> Associate a file type> select JPG and select Windows Photo Viewer. Repeat for JPEG and JPE. Was this reply helpful?
As Steve H said you can't just use file:///data/data/com.droidstogo.boom1/files/parked.jpg for that. It's your application private directory and camera can't write there. You can use some SD card file for example - it's available for all.
As stealthcopter said, intent extra is just MediaStore.EXTRA_OUTPUT without your package name.
Not an issue just FYI. I guess none of the permissions you specified are actually required for this operation.
Here's my code sample:
final int REQUEST_FROM_CAMERA=1;
private File getTempFile()
{
//it will return /sdcard/image.tmp
return new File(Environment.getExternalStorageDirectory(), "image.tmp");
}
private void getPhotoClick()
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(getTempFile()));
startActivityForResult(intent, REQUEST_FROM_CAMERA);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_FROM_CAMERA && resultCode == RESULT_OK) {
InputStream is=null;
File file=getTempFile();
try {
is=new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
//On HTC Hero the requested file will not be created. Because HTC Hero has custom camera
//app implementation and it works another way. It doesn't write to a file but instead
//it writes to media gallery and returns uri in intent. More info can be found here:
//http://stackoverflow.com/questions/1910608/android-actionimagecapture-intent
//http://code.google.com/p/android/issues/detail?id=1480
//So here's the workaround:
if(is==null){
try {
Uri u = data.getData();
is=getContentResolver().openInputStream(u);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
//Now "is" stream contains the required photo, you can process it
DoSomeProcessing(is);
//don't forget to remove the temp file when it's not required.
}
}
Is it because you've added an extra dot:
intent.putExtra("com.droidstogo.boom1."
Instead of:
intent.putExtra("com.droidstogo.boom1"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With