当我开始相机 Intent 时,我给它一个我希望它使用的文件名。当我在手机上获取它时,它使用手机的默认文件名。这没有帮助,因为我稍后需要在应用程序中使用图像名称。
相机 Intent 代码...
public void onClick(View view) {
String currentDateTimeString = DateFormat.getDateInstance().format(new Date());
System.out.println(currentDateTimeString);
filename = ("/sdcard/" + currentDateTimeString + ".jpg");
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), filename);
outputFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, TAKE_PICTURE);
filetype = "image/jpeg";
}
最佳答案
詹姆斯,
这是我用来捕获图像并将其保存到我选择的位置(带有我的应用程序名称的子文件夹)的功能。
public void imageFromCamera() {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
Log.d(TAG, "No SDCARD");
} else {
mImageFile = new File(Environment.getExternalStorageDirectory()+File.separator+"MyApp",
"PIC"+System.currentTimeMillis()+".jpg");
mTempImagePath = mImageFile.getAbsolutePath();
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mImageFile));
startActivityForResult(intent, TAKE_PICTURE);
}
}
关于android - 相机 Intent 安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5395674/