2011-07-14 18 views
10

我讀過的例子來做到這一點:如何獲得的位圖提供一個URI,java.io.FileNotFoundException:沒有內容提供商:/sdcard/Hello/1310610722879.jpg

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{ 
    super.onActivityResult(requestCode, resultCode, data); 
    if (resultCode == RESULT_OK) 
    { 
     Uri imageUri = data.getData(); 
     Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(),    imageUri); 
    } 
} 

,但我得到的java .io.FileNotFoundException:沒有內容提供商:/sdcard/Hello/1310610722879.jpg

我的代碼是在這裏:

Uri uri1 = Uri.parse(Config.getPhotoPath(this));     
try { 
    Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri1); 
    attachButton.setImageBitmap(bitmap); 
} catch (Exception e) { 
    // TODO: handle exception 
    e.printStackTrace(); 
} 

任何想法如何使它工作嗎?

好吧,我搞砸左右,我只好這樣做:

Uri uri1 = Uri.parse("file://" + Config.getPhotoPath(this)); 

回答

22

好吧,我搞砸左右,我只好這樣做:

Uri uri1 = Uri.parse("file://" + Config.getPhotoPath(this)); 
+0

這將是非常好的,他們可以添加MIME類型需要手動添加在API文檔中,而不僅僅是添加RFC 2396兼容:/ – amIT

+0

我不能fin d方法Config.getPhotoPath(),你也沒有在你的代碼中指定imageUri,你仍然能夠檢索圖像? – akshay7692

6

或者你也可以做

File file = new file(Config.getPhotoPath(this)); 
Uri uri1 = Uri.fromFile(file);