【问题标题】:fileNotFoundException camera intent - AndroidfileNotFoundException 相机意图 - Android
【发布时间】:2014-01-29 10:19:11
【问题描述】:

此相机意图是否将文件保存到 imageUri?我从这里获取此代码:How to take a photo, save it and get the photo in Android

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
    "fname_" + String.valueOf(System.currentTimeMillis()) + ".jpg"));

intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, CAMERA_REQUEST);

在 onActivityResult()...

else if ((requestCode == CAMERA_REQUEST) && (resultcode == -1)) {
    Uri selectedImage = imageUri;
    mProfilePicPath = selectedImage.toString();
    mPortraitPhoto = ih.decodeSampledBitmapFromImagePath(mProfilePicPath, 
        GlobalConstants.PROFILE_PICTURE_RESOLUTION, 
        GlobalConstants.PROFILE_PICTURE_RESOLUTION);

mProfilePicPath 不是有效的文件路径(未找到)。

【问题讨论】:

    标签: android android-intent camera filenotfoundexception


    【解决方案1】:

    为了获取图片的路径,需要使用Uri的另一种方法:

    mProfilePicPath = selectedImage.getPath();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-11
      • 2011-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多