Camera Intent not returning to calling Activity - android

I have read a lot of questions regarding this problem. Some are similar to what I am experiencing; I have tried the answers with no success. The code works on a HTC Android 4.2 and doesn't work on a Nexus 7 Android 4.4. I have modified the storage directory to work on android 4.4, so this isn't the problem.
The camera intent never returns if I use
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
and does return if I use
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoFile);
but it doesn't save the file.
Here is the full code.
Call the intent
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(manager) != null)
{
try
{
final File photoFile = createImageFile();
if (photoFile != null)
{
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
//takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoFile);
startActivityForResult(takePictureIntent, 1);
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
The file name
private File createImageFile() throws IOException
{
if (mStorageDirectory == null)
{
createInitialStorageDirectory();
setupFolders();
mScrollList.notifyDataSetInvalidated();
}
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "slide_" + timeStamp;
File storageDir = new File(mStorageDirectory);
File image = File.createTempFile(imageFileName, ".jpg", storageDir);
// image.setWritable(true, false);
// Save a path for use with ACTION_VIEW intents
mCurrentPhotoPath = image.getAbsolutePath();
return image;
}
The callback function
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1 && resultCode == -1)
{
}
}
The root directory plus the save directory
static String mBasePath = "/slides/";
private String getRootDirectory()
{
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state))
{
if (Build.VERSION.SDK_INT >= 19)
return mView.getContext().getFilesDir() + mBasePath;
else
return Environment.getExternalStorageDirectory() + "/Android/data/com.hdms.manager" + mBasePath;
//return Environment.getExternalStorageDirectory() + mBasePath;
}
return mBasePath;
}
Any thoughts would be appreciated.

In my case, it did not return because the output file was inside a folder which I have not created yet.
If it is the case for someone else, do this before starting anintent:
file.getParentFile().mkdirs();

So I have found a solution to my problem. If a file doesn't exist then the Camera Activity will not return. I guess the reason that it doesn't work on 4.4 is the change to the files system. I am not saving the image to the media gallery and loading the file back into my apps directory. The media file is then deleted. The reason that I don't leave it in the media directory, is when the app is deleted so will the images be deleted.
Here is the new code. First the intent call
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(manager) != null)
{
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "New Picture");
values.put(MediaStore.Images.Media.DESCRIPTION,"From your Camera");
Uri mImageUri = App.mApplication.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
mCurrentPhotoPath = mImageUri.getPath();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
startActivityForResult(takePictureIntent, 1);
}
Then the callback.
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1 && resultCode == -1)
{
if (data != null)
mCurrentPhotoPath = String.valueOf(data.getData());
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = App.mApplication.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, filePathColumn, null, null, null);
if (cursor == null)
return;
// find the file in the media area
cursor.moveToLast();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
File source = new File(filePath);
cursor.close();
// create the destination file
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "slide_" + timeStamp;
File destination = new File(mStorageDirectory, imageFileName + ".jpg");
// copy the data
if (source.exists())
{
try
{
FileChannel src = new FileInputStream(source).getChannel();
FileChannel dst = new FileOutputStream(destination).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
source.delete();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}

In our scenario our app is able to launch the camera app either via a 'button' click or an 'imageview' click. When using the button route the camera app correctly returned to the calling Activity as expected, however when tapping the imageview the results were inconsistent - sometimes it would return and sometimes the back button had to be tapped several times.
Turns out the solution was my oversight: I was not removing the event handler for the imageview in the OnPause method - once I did then it worked perfectly.

Related

Image size and dimensions reduce when I capture from camera

Using this to open camera:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_CAMERA);
and in OnActivityResult:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (data != null) {
if (requestCode == REQUEST_CAMERA && resultCode == RESULT_OK)
{
onCaptureImageResult(data);
}
}
private void onCaptureImageResult(Intent data) {
if (data != null) {
cameraBitMap = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
cameraBitMap.compress(Bitmap.CompressFormat.JPEG,100, bytes);
cameraFilePath = new File(Environment.getExternalStorageDirectory(),
System.currentTimeMillis() + ".jpg");
FileOutputStream fo;
try {
cameraFilePath.createNewFile();
fo = new FileOutputStream(cameraFilePath);
fo.write(bytes.toByteArray());
fo.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(cameraFilePath.getAbsolutePath(), options);
imageHeight = options.outHeight;
imageWidth = options.outWidth;
camImagePath = String.valueOf(cameraFilePath);
String fileName = camImagePath.substring(camImagePath.lastIndexOf("/") + 1);
txt_FileName.setText(fileName);
txt_FileName.setVisibility(View.VISIBLE);
btn_ImageTest.setImageBitmap(cameraBitMap);
}
}
I want the original size image to display when I capture it from the camera.
Use Intent like this. Here first give image name .
//declare globally
private static final int CAMERA_CODE = 101 ;
private Uri mImageCaptureUri;
Start Intent as below.
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp1.jpg");
if (f.exists()) {
f.delete();
}
mImageCaptureUri = Uri.fromFile(f);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
startActivityForResult(intent, CAMERA_CODE);
And in onActivityResult :
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_CODE && resultCode == RESULT_OK) {
System.out.println("Camera Image URI : " + mImageCaptureUri);
String path = mImageCaptureUri.getPath();
if (new File(path).exists()) {
Toast.makeText(MainActivity.this, "Path is Exists..", Toast.LENGTH_LONG).show();
}
btn_ImageTest.setImageURI(mImageCaptureUri);
}
}
You need to create temporary file before you start Camera Activity Intent.
Anything that using below code or similar like that after you take image using camera actually is a thumbnail image which is reduced the original quality.
This is the code that I meant:
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
mImageView.setImageBitmap(imageBitmap);
Refer Here for more info
This are the solution that you want
First You need to create temporary file.
Convert the temporary file into URI
Pass URI data to Camera intent by using putExtra method.
Open Camera Activity intent.
Handle onActivityResult if user cancel or accept the image from Camera Activity intent.
Below are the method you can use for step by step mentioned above.
Create Temporary File.
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = image.getAbsolutePath();
return image;
}
Convert Temporary file to URI and invoke camera activity intent.
static final int REQUEST_TAKE_PHOTO = 1;
Uri photoURI;
File photoFile;
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
...
}
// Continue only if the File was successfully created
if (photoFile != null) {
photoURI = FileProvider.getUriForFile(this,
"com.example.android.fileprovider",
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
Now you already have File location path created before Camera Activity intent called. You can handle RESULT_OK(Show image) or RESULT_CANCELED(Delete temporary image).
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
mImageView.setImageURI(photoURI );
}else{
photoFile.delete();
}
}
*Take note on getUriForFile which returns a content:// URI. For more recent apps targeting Android 7.0 (API level 24) and higher, passing a file:// URI across a package boundary causes a FileUriExposedException. Therefore, we now present a more generic way of storing images using a FileProvider.
Full documentation is here for reference.
Taking Photo Simply

Android - Taking Photos from camera storing photo at 2 paths

I am able to save a full-size photo from the camera at the specified location. However, the photo is being saved at 2 paths - one specified by code, second sd card DCIM folder.
Below is the code to get a full-size photo, it is in Activity and fileUri and mFilePath are class level variables.
private void openCamera() {
Intent takePictureIntent = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE);
File photoFile = null;
try {
photoFile = createFile();
} catch (IOException e) {
e.printStackTrace();
}
if (photoFile != null) {
fileUri = FileProvider.getUriForFile(context, AUTHORITY, photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
fileUri);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent,
REQUEST_IMAGE_CAPTURE);
}
}
}
private File createFile() throws IOException {
String state = Environment.getExternalStorageState();
File storageDir;
if (state.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) {
storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
} else {
storageDir = getFilesDir();
}
if (!storageDir.exists()) {
storageDir.mkdirs();
}
File image = File.createTempFile(“app” + System.currentTimeMillis(),
".jpg", storageDir);
mFilePath = image.getAbsolutePath();
return image;
}
private void galleryAddPic() {
MediaScannerConnection.scanFile(this, new String[]{
mFilePath},
null, new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_IMAGE_CAPTURE) {
galleryAddPic();
}
}
I am not sure is this device or platform specific. I am testing this on Moto G (2nd generation) and 5.0 Android OS. I have tried changing the storage setting for camera app but it always saves at 2 paths. I don't want it to get save at sd card DCIM folder. Has anyone faced such kind of issue? Any idea how to solve this?
Edit: I tried on Samsung's mobile which has 7.0 OS. There this behavior does not exist. Taken picture is getting save only at the specified path.

Open camera take photo and set it in image view in PopupWindow - android

I have a PopupWindow in Android, and inside it I have a imageview. When I press the imageview I want to open the camera take a photo and when I comeback to set photo for imageview's background.
The problem is when I comeback(onActivityResult), the popupwindow is dismiss(), and the imageView background is default.
imageView#onClick:
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (cameraIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
Log.i(TAG, "IOException");
}
// Continue only if the File was successfully created
if (photoFile != null) {
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
}
createImageFile() function
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, // prefix
".jpg", // suffix
storageDir // directory
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = "file:" + image.getAbsolutePath();
editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();
editor.putString("picture_path", mCurrentPhotoPath);
editor.commit();
return image;
}
#onActivityResult
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
try {
prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
mCurrentPhotoPath = prefs.getString("picture_path", null);
bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.parse(mCurrentPhotoPath));
add_photo.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
}
I used Sharedpreferences to avoid null on mCurrentPhotoPath .
Assuming the problem is that MediaStore.Images.Media.getBitmap is returning null, it is because it is meant to be used to retrieve an Image from URL handled by some app in some ContentResolver, which is not the case in your implementation.
In your implementation you're storing the image on devices filesystem which you can retrieve with BitmapFactorys decodeFile method that returns the bitmap.

why does mediastore take the last-1th picture from the gallery

Hello!
I have a problem between the picture gallery and the mediastore in my android application when i use the camera intent in my fragment.
I checked on the android website to learn how to take a picture in a fragment and on some forums to know how to get the last picture took but the media store always give me the last-1th picture as if it was not able to find the last picture.
This is my code :
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
Log.i(LOG_TAG,"ERRRRROR: "+ex.toString());
}
if (photoFile != null) {
mCurrentPhotoPath = "file:" +photoFile.getAbsolutePath();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, REQ_CAMERA_PICTURE);
}
}
private void galleryAddPic() {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(mCurrentPhotoPath);
Uri contentUri = Uri.fromFile(f);
mCurrentPhotoUri = contentUri;
mediaScanIntent.setData(contentUri);
getActivity().sendBroadcast(mediaScanIntent);
Log.d(LOG_TAG,"Photo SAVED");
}
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
mCurrentPhotoAbsolutePath = image.getAbsolutePath();
Log.i(LOG_TAG,"image path : "+image.getAbsolutePath());
return image;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQ_CAMERA_PICTURE)
{
if (resultCode == Activity.RESULT_OK)
{
galleryAddPic();
String filePath = getActivity().getPreferences(Context.MODE_PRIVATE).getString(TMP_PHOTO_FILE_LATEST_KEY, null);
handleCameraPicture(mCurrentPhotoUri.toString());
}
else
{
clearCurrentActionData();
}
}
}
private String getLastImagePath() {
String[] projection = new String[]{
MediaStore.Images.ImageColumns._ID,
MediaStore.Images.ImageColumns.DATA,
MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME,
MediaStore.Images.ImageColumns.DATE_TAKEN,
MediaStore.Images.ImageColumns.MIME_TYPE
};
final Cursor cursor = getActivity().getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null,null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");
if (cursor.moveToFirst()) {
String imageLocation = cursor.getString(1);
File imageFile = new File(imageLocation);
Bitmap bm = BitmapFactory.decodeFile(imageLocation);
return imageFile.getPath().toString();
}
else{
return "";
}
}
The problem occurs HERE when i try to get the last image path
private void handleCameraPicture(String pictureFileUri)
{
_currentDataObjectBuilder.addParameter(DataObject.Parameter.IMAGE, String.valueOf(getFileCount()));
//create a copy of the file into the internal storage
final File pictureFile = new File(pictureFileUri);
Log.d(LOG_TAG,"picture file uri : "+pictureFileUri.toString());
FileOutputStream fos =null;
byte[] pictureData = new byte[0];
try
{
pictureData = compressImage(getLastImagePath());
fos = getActivity().openFileOutput(String.valueOf(getFileCount()), Context.MODE_PRIVATE);
fos.write(pictureData);
Log.i(LOG_TAG,"SETTING FILE OUTPUT STREAM");
}
catch (IOException e)
{
e.printStackTrace();
}
finally {
try {
fos.close();
pictureFile.delete();
} catch (IOException e) {
e.printStackTrace();
}
}
if (_currentAction.equals(Action.PICTURE_CAPTION) || _currentAction.equals(Action.ARCHIVE))
{
showMessageView();
}
else
{
sendCurrentActionData();
}
}
The handleCameraPicture function allows me to send the "last picture" to an external website.
I don't know what i do wrong so please help me! I'm gonna lose my mind else...
Thank you!
Thomas
Wouw!
I finally found the solution, actually the uri when i created the picture was different from the one when i tried to save the picture in the gallery so my cursor dropped a null pointer exception.
I updated my GalleryAddPic function to
private void galleryAddPic(Uri uri) {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
mCurrentPhotoUri = uri;
mediaScanIntent.setData(uri);
getActivity().sendBroadcast(mediaScanIntent);
Log.d(LOG_TAG,"Photo SAVED");
}
And now everything works fine!

Weird issues with Samsung S3 native camera for result crashing

My app has the following code to invoke a capture from the native camera; startActivityForResult
It has been tested on a nexus 5, HTC 1, nexus 7, Samsung S4, and Samsung S3. It works great on every device except, the S3. On the S3 the app crashed on return to the starting activity
the crash:
03-07 13:09:21.297: E/ActivityThread(6535): Activity com.DRPMapViewActivity
has leaked ServiceConnection android.media.MediaScannerConnection#42bd73d8 that
was originally bound here
03-07 13:09:21.297: E/ActivityThread(6535): android.app.ServiceConnectionLeaked:
Activity com.DRPMapViewActivity has leaked ServiceConnection
android.media.MediaScannerConnection#42bd73d8 that was originally
bound here
my code
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
.format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = new File(g.kPhotoDirectory);
// File storageDir = new
// File(Environment.getExternalStoragePublicDirectory(
// Environment.DIRECTORY_DCIM), "Drop");
storageDir.mkdirs();
File image = File.createTempFile(imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = image.getAbsolutePath();
return image;
}
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
photoFileFromCapture = null;
try {
photoFileFromCapture = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
}
// Continue only if the File was successfully created
if (photoFileFromCapture != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFileFromCapture));
startActivityForResult(takePictureIntent,
g.kRequestImageCaptureCode);
}
}
}
private void dispatchChoosePictureIntent() {
Intent i = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
i.setType("image/*");
// Intent chooserIntent = Intent.createChooser(i,"Image Chooser");
startActivityForResult(i, g.kRequestImageChooserCode);
}
my onActivityResult looks like this:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == g.kGenericRequestCode) {
if (resultCode == g.kKillMeResultCode) {
finish();
}
Log.v("activityResult", "requestcode:" + requestCode
+ " resultCode:" + resultCode + " data:" + data);
super.onActivityResult(requestCode, resultCode, data);
}
if (requestCode == g.kRequestImageChooserCode
&& resultCode == Activity.RESULT_OK) {
Uri imageUri = data.getData();
Log.v("CAPTURE", "uri:" + imageUri);
String filePath = getRealPathFromURI(imageUri);
Intent i = new Intent(DRPMapViewActivity.this,
DRPCreateDropActivity.class);
i.putExtra("USER", _user);
i.putExtra("LATLNG", getLocationForCreateDrop());
i.putExtra("FILE_PATH", filePath);
i.putExtra("TYPE", CreateDropType.kImageFile);
startActivity(i);
overridePendingTransition(R.anim.slide_in_right,
R.anim.slide_out_left);
}
if (requestCode == g.kRequestImageCaptureCode) {
Log.v("CAPTURE RESULT", "result:" + resultCode);
if(resultCode== Activity.RESULT_OK){
MediaScannerConnection.scanFile(this,
new String[] { mCurrentPhotoPath }, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
}
});
Intent i = new Intent(DRPMapViewActivity.this,
DRPCreateDropActivity.class);
i.putExtra("USER", _user);
i.putExtra("LATLNG", getLocationForCreateDrop());
i.putExtra("FILE_PATH", mCurrentPhotoPath);
i.putExtra("TYPE", CreateDropType.kImageFile);
startActivity(i);
overridePendingTransition(R.anim.slide_in_right,
R.anim.slide_out_left);
if (data != null) {
Log.v("CAPTURE RESULT", "data:" + data.getData());
}
}
}
}
So the problem seems to be that for what ever reason the Samsung S3's native camera is not returning Data when setting result. So while you get the appropriate result code there is no actual data being passed back. To fix this in my result listener, i check to see if the data is null. The data is suppose to be the file path of the photo taken. If the path is null && the result code is RESULT_OK, I just reiterate through the directory that I told the camera to save the picture in and get the path of the last file created.:
if(heroFilePath==null){
File dir = new File(g.kPhotoDirectory);
File[] files = dir.listFiles();
File lastModifiedFile = files[0];
for (int i = 1; i < files.length; i++) {
if (lastModifiedFile.lastModified() < files[i].lastModified()) {
lastModifiedFile = files[i];
}
}
heroFilePath = lastModifiedFile.getAbsolutePath();
}

Categories

Resources