Android中的Uri错误

时间:2013-06-25 09:04:47

标签: android camera uri

你好,任何人都可以帮我解决这个问题。我在这一行收到错误文件imageFile = new File(photoUri); 说构造函数File(photoUri)是未定义的,即使我在调用它的方法上有这个构造函数。这是我的代码。

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{
        if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQ){
    if (resultCode == RESULT_OK) {
           Uri photoUri = null;
        if (data == null){
            Toast.makeText(this, "Image saved successfully", Toast.LENGTH_LONG).show();
            photoUri = fileUri;
         } else {
                photoUri = data.getData();
                    Toast.makeText(this, "Image saved successfully in: " + data.getData(), Toast.LENGTH_LONG).show();
                    }
                showPhoto(photoUri);
        } else if (resultCode == RESULT_CANCELED) 
            {
              Toast.makeText(this, "Cancelled", Toast.LENGTH_SHORT).show();
            } else 
                {
                  Toast.makeText(this, "Callout for image capture failed!",  Toast.LENGTH_LONG).show();
                }
      }

    }

private void showPhoto(Uri photoUri) 
{

    File imageFile = new File(photoUri);
      if (imageFile.exists())
      {
            Drawable oldDrawable = photoImage.getDrawable();
            if (oldDrawable != null) { ((BitmapDrawable)oldDrawable).getBitmap().recycle(); 
       }
            Bitmap bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath());
            BitmapDrawable drawable = new BitmapDrawable(this.getResources(), bitmap);
            photoImage.setScaleType(ImageView.ScaleType.FIT_CENTER);
            photoImage.setImageDrawable(drawable);
 }  

}

1 个答案:

答案 0 :(得分:0)

toString()实例

上调用photoUri
showPhoto(photoUri.toString());

Uri.toString()返回此URI的编码字符串表示形式。