簡體   English   中英

無法在Android中搜索應用程序特定文件的原因和解決方案

[英]Reason for not being able to search the app-specific files in Android and solution

我正在構建一個反應原生應用程序,其中包括pdf 文件下載圖像上傳功能。

對於文件下載,我使用react-native-fsreact-native-html-to-pdf並且對於圖像上傳,我使用axiosreact-native-image-crop- picker 。

我很久以前就已經實現了圖像上傳功能,它就像魅力一樣。

這些天來,我已經實現了pdf 文件下載功能,並且運行良好。

問題

  • 圖像上傳不再起作用。

react-native log-android記錄的錯誤消息如下所示: Network error _response: 'Could not retrieve file for uri /storage/emulated/0/Android/data/packageName/files/Pictures/75a08b1a-98de-4811-8b44-453f6f2f9bf8.jpg',

  • 下載的 pdf 文件存在於特定於應用程序的文件夾中,但在 Android 文件管理器中無法找到。

下載 pdf 文件路徑是這樣的: /storage/emulated/0/Android/data/packageName/files/data/user/0/packageName/files/fileName.pdf我已經檢查過這肯定存在於確切的目錄中。

  • 其他應用程序(apks)特定文件可在 Android 文件管理器中發現。

我想知道的是

  • 為什么只有我的 react native 包目錄無法在文件管理器中發現,而其他應用程序特定的文件卻可以?
  • 我錯過了哪些設置或做錯了什么?

我為測試圖片上傳做了什么

  • 此功能運行良好,因此我從 Github 下載了舊的提交版本並重建了所有應用程序。 並嘗試上傳圖片,但出現了同樣的問題。

我假設的是

  • 我記得很久以前我已經運行與帶有 tcp 端口的adb相關的命令行來修復問題。(我不記得那個命令行是什么,我做了谷歌並運行命令行),我假設這可能是一個問題。
  • 所有問題文件都存在於同一目錄中:由 android 分配的應用程序特定目錄。 我已閱讀此android 開發文檔 所以我的想法是首先,向安卓手機反應原生請求圖像,其次,安卓手機無法訪問包文件夾,第三,所以安卓手機無法獲取該圖像並返回網絡錯誤:無法檢索圖像文件。
  • Android 手機無權訪問 react native 包目錄,所以在文件管理器中找不到 pdf 文件。

實際代碼

  • AndroidMainfest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="packageName">
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.CAMERA"/>
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
  <uses-feature android:name="android.hardware.camera" android:required="false"/>
  <uses-feature android:name="android.hardware.camera.front" android:required="false"/>
  <application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false" android:theme="@style/AppTheme" android:usesCleartextTraffic="true" android:requestLegacyExternalStorage="true">
    <activity android:exported="true" android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize">
      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>
      <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:scheme="invitation"/>
      </intent-filter>
      <intent-filter>
          <action android:name="android.intent.action.VIEW"/>
          <category android:name="android.intent.category.DEFAULT"/>
          <category android:name="android.intent.category.BROWSABLE"/>
          <data
              android:host="deeplinkUrl"
              android:scheme="https"/>
      </intent-filter>
    </activity>

    
    <!--  Facebook login  -->
    <activity android:name="com.facebook.FacebookActivity"
        android:configChanges=
                "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:label="@string/app_name" />
    <activity
        android:name="com.facebook.CustomTabActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="@string/fb_login_protocol_scheme" />
        </intent-filter>
    </activity>
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
    <meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token"/>
    <!--  Facebook login  -->

  </application>
  <queries>
    <intent>
      <action android:name="android.intent.action.VIEW"/>
      <data android:mimeType="*/*"/>
    </intent>
  </queries>
</manifest>
  • android\app\src\main\res\xml\filepaths.xml (這是針對 android 11:這也是從 github 問題論壇復制的)
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
  <external-path name="appdownloads" path="Download/" />
  <external-path name="files" path="/" />
  <root-path name="root" path="." />
</paths>

我認為這與 Android 和本地 pc 設備有關。 如果您能告訴我們您的開發環境,那就太好了

暫無
暫無

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

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