Gallery Intent在Android 4.0.3上不起作用
这是我从图库中获取图像的代码Gallery Intent在Android 4.0.3上不起作用,android,android-layout,android-intent,android-gallery,Android,Android Layout,Android Intent,Android Gallery,这是我从图库中获取图像的代码 intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(intent, GALLERY_INTENT); 这是onActivit
intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, GALLERY_INTENT);
这是onActivityResult方法
这段代码在android 2.3.4版本上运行良好,但当我在4.0.3设备上测试这段代码时,它不工作,可能是什么问题?我已经解决了这个问题
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
ZootOutObject.objectUri = getImagePath();
intent.putExtra(MediaStore.EXTRA_OUTPUT, ZootOutObject.objectUri);
startActivityForResult(intent, CAMERA_INTENT);
如果requestcode==1&&resultCode==RESULT\u正常{
String pathName=Environment.getExternalStorageDirectory()+"/folder_name/image_zootout.jpg";
Intent intent = new Intent(getApplicationContext(),PhotoEditorActivity.class);
intent.putExtra("IMAGE_PATH", pathName);
intent.putExtra("OUTLET_ID", 0);
intent.putExtra("OUTLET_NAME", "");
startActivity(intent);
}
private Uri getImagePath() {
// If sd card is available
if(android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)){
String path = Environment.getExternalStorageDirectory() .getAbsolutePath();
filename = "image_zootout.jpg";
path += "/folder_name";
File file = new File(path);
if (!file.isDirectory()) {
file.mkdirs();
}
path += "/" + filename;
File imageFile = new File(path);
if (!imageFile.exists()) {
try {
imageFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
return Uri.fromFile(imageFile);
}else{ // If sd card is not available
return null;
}
}
当你说:它不工作时,你的确切意思是什么?你能更具体地说明它做什么和不做什么吗?例如,是否引发了异常?或者它只是没有打开库?在你试图激发意图时,Logcat中是否有任何消息?方法中的imageFilePath为我提供了到imag的正确路径在4.0.3版本中,你有它的ans吗?如果有,请分享我也有同样的问题intent intent intent=new intent和roid.provider.MediaStore.ACTION\u IMAGE\u CAPTURE;ZootOutObject.objectUri=getImagePath;intent.putExtraMediaStore.EXTRA\u OUTPUT,ZootOutObject.objectstartactivityforresultentint,摄像机意图;
String pathName=Environment.getExternalStorageDirectory()+"/folder_name/image_zootout.jpg";
Intent intent = new Intent(getApplicationContext(),PhotoEditorActivity.class);
intent.putExtra("IMAGE_PATH", pathName);
intent.putExtra("OUTLET_ID", 0);
intent.putExtra("OUTLET_NAME", "");
startActivity(intent);
}
private Uri getImagePath() {
// If sd card is available
if(android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)){
String path = Environment.getExternalStorageDirectory() .getAbsolutePath();
filename = "image_zootout.jpg";
path += "/folder_name";
File file = new File(path);
if (!file.isDirectory()) {
file.mkdirs();
}
path += "/" + filename;
File imageFile = new File(path);
if (!imageFile.exists()) {
try {
imageFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
return Uri.fromFile(imageFile);
}else{ // If sd card is not available
return null;
}
}