I'm using a loadfromgallery
function to load and crop an image from gallery,
but sometimes it doesn't works.
It seems to don't work on devices without SDCard (I tested it on various devices, in my i9000+CM10.1+semaphore with and w/out always works, in a tablet with android>4.0 doesn't works)
Can somebody help me?
This is my onActivityResult
method:
protected void onActivityResult(int requestCode, int resultCode,Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch (requestCode) {
case REQ_CODE_PICK_IMAGE:
if (resultCode == RESULT_OK) {
if (imageReturnedIntent!=null){
getTempFile();
String filePath= Environment.getExternalStorageDirectory()+ "/temp/"+TEMP_PHOTO_FILE;
System.out.println("path "+filePath);
Bitmap selectedImage = BitmapFactory.decodeFile(filePath);
bitmapdrawable = new BitmapDrawable(selectedImage);
generator_imagen.setImageDrawable(bitmapdrawable);
app_gestorVistas("GENERATE");
app_posicionGrid=9999;
}
}
}}
This is the function:
public void loadfromgallery(){ //TODO LOAD FROM GALLERY
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
photoPickerIntent.setType("image/*");
photoPickerIntent.putExtra("crop", "true");
photoPickerIntent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri());
photoPickerIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
startActivityForResult(photoPickerIntent, REQ_CODE_PICK_IMAGE);
}
private Uri getTempUri() {
return Uri.fromFile(getTempFile());
}
private File getTempFile() {
if (isSDCARDMounted()) {
File f = new File(Environment.getExternalStorageDirectory(),"/temp/"+TEMP_PHOTO_FILE);
try {f.createNewFile();}
catch (IOException e) {}
return f;
} else {
return null;
}
}
private boolean isSDCARDMounted(){
String status = Environment.getExternalStorageState();
if (status.equals(Environment.MEDIA_MOUNTED))
return true;
return false;
}
private static final String TEMP_PHOTO_FILE = "mprt_img.jpg";
This is my filtered logcat (Lifecycle)
01-27 13:34:29.476: V/EVENTO(4630): STATE: onCreate
01-27 13:34:36.261: V/EVENTO(4630): STATE: onStart
---APP BUSY--
01-27 13:34:47.296: V/EVENTO(4630): STATE: onStop
--STOP APP AN DSHOW IMAGEPICKER---
01-27 13:35:01.316: V/EVENTO(4630): STATE: onRestart
01-27 13:35:01.332: V/EVENTO(4630): STATE: onStart