【问题标题】:How to create a file using content?如何使用内容创建文件?
【发布时间】:2012-12-05 15:45:50
【问题描述】:

拍摄照片后,我收到一个Intent data,我从中检索一个Uri

Uri contentURI = data.getData();

内容 Uri 是 content://media/external/images/media/5576

使用此contentURI 我需要将文件保存到 SD 卡,请告知如何。非常感谢您的帮助。

【问题讨论】:

  • 从那个地址返回什么,txt,jpg..?
  • 我想,只要是从Camera获取的,应该是jpg。内容://媒体/外部/图像/媒体/5576
  • 看起来这个链接讨论了它stackoverflow.com/questions/7266572/…

标签: android


【解决方案1】:

当您使用Intent 从相机拍照时,为什么不将照片保存到文件夹中?这会加快速度。试试这段代码,例如:

Intent getCameraImage = new Intent("android.media.action.IMAGE_CAPTURE");

File cameraFolder;

if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
    cameraFolder = new File(android.os.Environment.getExternalStorageDirectory(),"CHANGE_TO_YOUR_FOLDER_NAME/camera");
else
    cameraFolder= StatusUpdate.this.getCacheDir();
if(!cameraFolder.exists())
    cameraFolder.mkdirs();

File photo = new File(Environment.getExternalStorageDirectory(), "CHANGE_TO_YOUR_FOLDER_NAME/camera/camera_snap.jpg");
getCameraImage.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
Uri initialURI = Uri.fromFile(photo);

startActivityForResult(getCameraImage, 2);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-13
    • 1970-01-01
    • 2011-05-07
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 2020-05-27
    相关资源
    最近更新 更多