拍照保存并在Android中获取照片

时间:2016-12-12 22:26:16

标签: android android-camera

在我的应用程序中,用户可以通过选择现有照片或拍摄新照片将照片上传到服务器。当我拿一个新代码时,我有以下代码:

// Take a new photo
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File cameraFolder;

if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
    cameraFolder = new File(android.os.Environment.getExternalStorageDirectory(), "images/");
} else {
    cameraFolder = getCacheDir();
}

if (!cameraFolder.exists()) {
    cameraFolder.mkdirs();
}

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
String timeStamp = dateFormat.format(new Date());
String imageFileName = "picture_" + timeStamp + ".jpg";

File photo = new File(Environment.getExternalStorageDirectory(), "images/" + imageFileName);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
pictureUri = Uri.fromFile(photo);

startActivityForResult(takePictureIntent, ACTION_REQUEST_CAMERA);

上面代码的问题是照片保存到我需要的图库中。如何让用户拍照并将其保存并提交到我的服务器?

0 个答案:

没有答案