java.lang.IllegalArgumentException:android.content.ContentResolver.delete中的未知URL文件

时间:2014-10-09 12:43:30

标签: java android

获得上述错误

builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {

                        if (mImageCaptureUri != null)
                        {
                            //exception at below line
                            getContentResolver().delete(mImageCaptureUri, null,null);
                            mImageCaptureUri = null;
                        }
                    }
                });

我尝试检查文件是否存在new File(mImageCaptureUri.getPath()).exists()它是否存在,但我仍然得到例外

java.lang.IllegalArgumentException: Unknown URL file:///storage/sdcard0/tmp_avatar_1412858553212.jpg    
at android.content.ContentResolver.delete(ContentResolver.java:984) 

1 个答案:

答案 0 :(得分:2)

  

我尝试通过新文件检查文件是否存在(mImageCaptureUri.getPath())。exists()它存在

请注意there is no requirement that a Uri point to a file that you can access

  

我仍然得到例外

java.lang.IllegalArgumentException: Unknown URL file:///storage/sdcard0/tmp_avatar_1412858553212.jpg at android.content.ContentResolver.delete(ContentResolver.java:984) 

ContentResolver主要针对content://计划。对于file://方案,您可能需要自己尝试直接删除该文件。