簡體   English   中英

Android-無法訪問下載的文件

[英]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>

我想念什么嗎?

一切都在內部存儲中

並非從Android SDK的角度來看。 就Android SDK而言, 內部存儲不是外部存儲 ,也不是可移動存儲

該文件將下載到/storage/emulated/0/Android/data/com.example.max.lucas/files/filename

假設您的應用程序以設備的主用戶帳戶運行(通常是這種情況),則相當於new File(getExternalFilesDir(null), "filename") )。

getFilesDir()指向一個位置,您可以在其中將任何文件存儲在應用程序內部存儲的角落。 您的文件位於應用程序特定位置的外部存儲中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM