[英]Android - can't access a downloaded file
我正在嘗試編寫一個使用Android DownloadManager下載文件的應用程序,下載完成后,我想編輯該文件。 嘗試使用以下代碼訪問文件時遇到問題:
File file = new File(context.getFilesDir(), filename);
file.exists() - returns false even though I can view the file with the File Manager app
注意:以上OnRecieve()
行是在OnRecieve()
方法中的BroadcastReciever中編寫的,而我正在使用的設備沒有外部存儲。
我試圖檢查其中代碼通過查找文件createNewFile()
方法,但同時,使exists()
方法返回true
我不能為我的生活找到在文件管理器應用程序創建的文件。
我還嘗試了以下URI:
/storage/emulated/0/Android/data/com.example.max.lucas/files/filename
/emulated/0/Android/data/com.example.max.lucas/files/filename
/0/Android/data/com.example.max.lucas/files/filename
/Android/data/com.example.max.lucas/files/filename
/data/com.example.max.lucas/files/filename
/com.example.max.lucas/files/filename
/files/filename
/filename
但似乎沒有一個工作。
我的清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.max.lucas" >
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activities>.....</activities>
<receiver <- Where I'm trying to find and edit the file
android:name=".rcv_DownloadedFilesHandler"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
<action android:name="com.example.max.lucas"/>
</intent-filter>
</receiver>
</application>
我想念什么嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.