[英]How to delete an image from sd card
如何從SD卡中刪除圖像文件。 我試過了:
File file=new File(filepath);
file.delete();
但我無法刪除它。 當我嘗試在調試模式下檢查它時,file.delete()返回false。 我還在我的Manifest文件中添加了權限。
uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
我也嘗試過:
public abstract boolean deleteFile (String name)
來自andoid上下文的方法。 即使這樣也會失敗。
File file = new File(selectedFilePath);
boolean deleted = file.delete();
不要為sd-card存儲目錄傳遞靜態值,最好使用getExternalStorageDirectory()來檢索sd-card目錄的確切值。 (因為它可能是/ sdcard或/ mnt / sdcard所以):
String dirPath = Environment.getExternalStorageDirectory().getPath();
詳細示例如下: 檢查並獲取Android外部存儲目錄
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.