这是一个古老的话题,但是我会补充我的经验,也许有人会觉得这很有帮助
> 2019-11-12 20:05:50.178 27764-27764/com.strba.myapplicationx I/File: /storage/emulated/0/Android/data/com.strba.myapplicationx/files/Readings/JPEG_20191112_200550_4444350520538787768.jpg//file when it was created
2019-11-12 20:05:58.801 27764-27764/com.strba.myapplicationx I/File: content://com.strba.myapplicationx.fileprovider/my_images/JPEG_20191112_200550_4444350520538787768.jpg //same file when trying to delete it
解决方案1:
Uri uriDelete=Uri.parse (adapter.getNoteAt (viewHolder.getAdapterPosition ()).getImageuri ());//getter getImageuri on my object from adapter that returns String with content uri
在这里,我初始化内容解析器,并使用该URI的传递参数将其删除
ContentResolver contentResolver = getContentResolver ();
contentResolver.delete (uriDelete,null ,null );
solution2(这是我的第一个解决方案,我确实知道):内容解析器存在...
String path = "/storage/emulated/0/Android/data/com.strba.myapplicationx/files/Readings/" +
adapter.getNoteAt (viewHolder.getAdapterPosition ()).getImageuri ().substring (58);
File file = new File (path);
if (file != null) {
file.delete ();
}
希望这对编码愉快的人有所帮助
inputHandle.getImgPath(id)
是文件路径