我要做的是创建一个新文件夹并将相机捕获的图像保存在该文件夹中。我正在尝试使用以下片段来实现它:
public class DocsAdd extends Activity
{
private static int TAKE_PICTURE = 1;
private Uri outputFileUri;
Bitmap thumbnail;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
File filename;
try
{
long currentTime = System.currentTimeMillis();
String fileName = "img" + currentTime+".jpg";
String path = Environment.getExternalStorageDirectory().toString();
filename = new File(path + "/AutoistDiary/"+ fileName);
FileOutputStream out = new FileOutputStream(filename);
out.flush();
out.close();
MediaStore.Images.Media.insertImage(getContentResolver(),filename.getAbsolutePath(), filename.getName(), filename.getName());
outputFileUri = Uri.fromFile(filename);
}
catch (Exception e)
{
e.printStackTrace();
}
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, TAKE_PICTURE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == TAKE_PICTURE)
{
Uri imageUri = null;
if (data!=null)
{
if (data.hasExtra("data"))
{
thumbnail = data.getParcelableExtra("data");
Intent docsShow_intent=new Intent(this,DocsShow.class);
startActivity(docsShow_intent);
}
}
else
{
}
}
}
}
但是当我在 Optimus1 上运行它时,它没有向我的活动返回任何结果,遇到了一个链接Camera on Android Example,它说明了我目前面临的相同问题,因此可以帮助我解决这个问题。?