这是我用来创建意图的代码:
try {
file = createImageFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(file!= null)
{
Log.d(Tag,"absolute path: "+imageAbsolutePath);
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(file));
startActivityForResult(i, TAKE_PICTURE);
}
这是返回具有自定义名称和位置的文件的方法:
private File createImageFile() throws IOException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String currentDate = sdf.format(new Date());
SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm:ss");
String currentTime = sdf2.format(new Date());
String timeArray[] = currentTime.split(":");
String imageName = currentDate+" "+timeArray[0]+"-"+timeArray[1]+"-"+timeArray[2];
// create a File object for the parent directory
File Pictures = new File(Environment.getExternalStorageDirectory()+File.separator+"Pictures");
// have the object build the directory structure, if needed.
if (!Pictures.exists()) {
Pictures.mkdirs();
Log.d(Tag,"Pictures folder created: "+Pictures);
}else
{
Log.d(Tag,"Pictures folder Already Exists: "+Pictures);
}
// File image = File.createTempFile(imageName,".jpg",Pictures);
File image = new File (Pictures,imageName+".jpg" );
Log.d(Tag,"This is Image name: "+ imageName);
imageAbsolutePath = image.getAbsolutePath();
return image;
}
这是我使用的inActivityResult方法:
case TAKE_PICTURE:
if(resultCode == RESULT_OK)
{
galleryAddPic();
Bitmap imgBitmap=null;
try
{
imgBitmap = lessResolution(imageAbsolutePath);
}catch (Exception e)
{
e.printStackTrace();
}
if (imgBitmap!=null)
{
images.add(imgBitmap);
GridView grid = (GridView) findViewById(R.id.grid_view);
grid.setAdapter(new ImageAdapter(this));
}
所有这些方法适用于以下设备:摩托罗拉Xoom,摩托罗拉Droid,Razor,一些三星设备,但在三星Galaxy Ace s5830m(Android 2.3.6)中不起作用。 它正确地拍摄图像,但当它返回onActivityResult时没有任何反应。经过一些测试,我发现它没有显示任何东西,因为图像保存在DCIM / Camera文件夹而不是图片文件夹中,所以我做错了什么?。
答案 0 :(得分:0)
我有同样的问题,在某些手机中它正在工作而其他人没有,我在这个链接中找到了我的解决方案,我希望这可以帮到你: