我正在使用一个loadfromgallery
函数从图库中加载和裁剪图像,但有时它不起作用。
它似乎不适用于没有 SDCard 的设备(我在各种设备上对其进行了测试,在我的 i9000+CM10.1+semaphore 和 w/out 中始终有效,在 android>4.0 的平板电脑中无效)
有人可以帮助我吗?
这是我的onActivityResult
方法:
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;
}
}
}}
这是功能:
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";
这是我过滤的 logcat(生命周期)
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