I am having problem with storing the image from a camera intent. After hours of testing I finally realised that the problem I had was due to the fact that it was Sony Xperia S I was working on as my HTC desire worked correctly.
I want to take image, and then I want to retrieve it and conert it to byte array and sent it to a wcf.
This is how I try to achieve the storing image part:
How can this be fixed so it can be used on Sony Xperia S, I figure it is because it has an internal memory, not an external device. I have tried using cachedir but then the intent fails with error-code 0. With this code it does not fail, but no image is stored to the download directory but its saved to the gallary.
Solved: The problem was not in the storing of files, my windows explorer did not update the folders so I thought the files had not been saved. However! it was how I in the next step tried to grab the file, with File f = new File(imageUri.toString()); , this works on HTC Desire but not on Sony Xperia S!
I want to take image, and then I want to retrieve it and conert it to byte array and sent it to a wcf.
This is how I try to achieve the storing image part:
Code:
private File getCameraImageFile() {
String storageState = Environment.getExternalStorageState();
if (storageState.equals(Environment.MEDIA_MOUNTED)) {
String path = Environment.getExternalStorageDirectory() +
"" + File.separatorChar + "download"+ ""+ File.separatorChar+""+ "mypicture.jpg";
File photoFile = new File(path);
try {
if (!photoFile.exists()) {
photoFile.getParentFile().mkdirs();
photoFile.createNewFile();
}
} catch (IOException e) {
Log.e(TAG, "Could not create file.", e);
}
Log.i(TAG, "Got a file! " + path);
return photoFile;
} else {
Log.i(TAG, "External storage (SD card) is required. Current state: "
+ storageState);
// show some error dialog here
return null;
}
}
public void takePhoto(View view) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File file = getCameraImageFile();
imageUri = Uri.fromFile(file);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(cameraIntent, 32);
}
How can this be fixed so it can be used on Sony Xperia S, I figure it is because it has an internal memory, not an external device. I have tried using cachedir but then the intent fails with error-code 0. With this code it does not fail, but no image is stored to the download directory but its saved to the gallary.
Solved: The problem was not in the storing of files, my windows explorer did not update the folders so I thought the files had not been saved. However! it was how I in the next step tried to grab the file, with File f = new File(imageUri.toString()); , this works on HTC Desire but not on Sony Xperia S!