我试图从拍摄照片后获得完整的图像Fragment.
如果我使用文件(Uri.fromFile(file))中的Uri,拍摄照片并点击"确定"按钮后相机将不会退出(看起来无法写入Uri或谁知道什么).
使用File String,形式'/data/data/com.package.bla/cache/img198346262jpg',它不能正常工作(文件在那里,但它是空的,因为相机没有保存任何东西).
到目前为止我尝试了什么:
所以我不知道为什么图像没有被保存,并且已经花费/浪费了大量时间测试并弄清楚它为什么不起作用.
分段:
private void launchCamera() {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File outputDir = getActivity().getCacheDir();
File file = null;
try {
file = File.createTempFile("img", "jpg", outputDir);
} catch (IOException e) {
e.printStackTrace();
}
if (file != null) {
mImageUri = Uri.fromFile(file); //using Uri is not even exiting the camera
//mImageUri = File.toString(); //If I use String instead of an Uri, it works better …Run Code Online (Sandbox Code Playgroud)