【发布时间】:2012-01-23 18:20:27
【问题描述】:
我设法让photo1.jpg 保存到我在SD 卡上创建的Pictures/mockFolder,这是代码供以后参考。
public class CameraActivity extends Activity
{
final int PICTURE_ACTIVITY = 1;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/mockFolder/";
File newdir = new File(dir);
newdir.mkdirs();
String file = dir + "photo1.jpg";
File newfile = new File(file);
try {
newfile.createNewFile();
} catch (IOException e) {}
Uri outputFileUri = Uri.fromFile(newfile);
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(cameraIntent, PICTURE_ACTIVITY);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
AlertDialog msgDialog;
if (resultCode == RESULT_CANCELED) {
msgDialog = createAlertDialog("Alert", "Picture was not saved. Please try again.", "OK");
} else {
msgDialog = createAlertDialog("Alert", "Picture was saved successfully.", "OK");
}
msgDialog.show();
}
private AlertDialog createAlertDialog(String title, String msg, String buttonText){
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
AlertDialog msgDialog = dialogBuilder.create();
msgDialog.setTitle(title);
msgDialog.setMessage(msg);
msgDialog.setButton(buttonText, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int idx){
finish();
}
});
return msgDialog;
}
public void finish()
{
super.finish();
}
}
【问题讨论】:
标签: android camera save directory image