[英]How to write files on SD Card from Android API 24+
我有一個大問題。 我想將使用我的應用程序從 Internet 下載的一些文件保存到我的 SD 卡中,遵循以下路徑:
/storage/9016-4EF8/Android/data/com.my.application/files
但我不想在我的代碼中硬編碼這個字符串。 那么我該如何以編程方式進行呢? 我已經請求允許在外部存儲上寫入。
目前在我的代碼中有以下這段代碼:
File sdcard = new File(context.getExternalFilesDir(null).getAbsolutePath() + "/Video scaricati/");
但是有了它,我的應用程序將文件保存在里面:
/storage/emulated/0/Android/data/com.my.application/files/Video scaricati
它不在我的 SD 卡中。
我該怎么做?
取第二項返回的
File dirs[] =getExternalFilesDirs();
使用前檢查數組是否包含多個元素。 不是每個人都會放入 micro SD 卡。
嘗試像這樣更改為Environment.getExternalStorageDirectory()
new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Video scaricati/");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.