简体   繁体   English

无法在Android中搜索应用程序特定文件的原因和解决方案

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

I am building a react native app which includes pdf file download and image upload functionality.我正在构建一个反应原生应用程序,其中包括pdf 文件下载图像上传功能。

For doing file download, I am using react-native-fs and react-native-html-to-pdf and for image upload, I am using the axios and react-native-image-crop-picker .对于文件下载,我使用react-native-fsreact-native-html-to-pdf并且对于图像上传,我使用axiosreact-native-image-crop- picker 。

I have already implemented the image upload functionality long time ago and it worked like charm.我很久以前就已经实现了图像上传功能,它就像魅力一样。

In these days, I have implemented the pdf file download functionality and also it works well.这些天来,我已经实现了pdf 文件下载功能,并且运行良好。

PROBLEM问题

  • Image upload does not work anymore.图像上传不再起作用。

Error message which is logged by react-native log-android looks like this: Network error _response: 'Could not retrieve file for uri /storage/emulated/0/Android/data/packageName/files/Pictures/75a08b1a-98de-4811-8b44-453f6f2f9bf8.jpg', 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',

  • Downloaded pdf file is exist in app-specific folder but not discoverable in Android file manager.下载的 pdf 文件存在于特定于应用程序的文件夹中,但在 Android 文件管理器中无法找到。

Download pdf file path is like this: /storage/emulated/0/Android/data/packageName/files/data/user/0/packageName/files/fileName.pdf and I have checked this is definitely exist in exact directory.下载 pdf 文件路径是这样的: /storage/emulated/0/Android/data/packageName/files/data/user/0/packageName/files/fileName.pdf我已经检查过这肯定存在于确切的目录中。

  • Other apps(apks) specific files are discoverable in Android file manager.其他应用程序(apks)特定文件可在 Android 文件管理器中发现。

What I am wondering is我想知道的是

  • Why only my react native package directory is not able to discoverable in file manager while even other app specific files are able?为什么只有我的 react native 包目录无法在文件管理器中发现,而其他应用程序特定的文件却可以?
  • Which setup I have missed or done incorrect?我错过了哪些设置或做错了什么?

What I did for test image upload我为测试图片上传做了什么

  • This functionality worked well so I have downloaded old committed version from Github and rebuild all of app.此功能运行良好,因此我从 Github 下载了旧的提交版本并重建了所有应用程序。 and tried to upload the image, but the same issue appeared.并尝试上传图片,但出现了同样的问题。

What I assumed is我假设的是

  • I can remember I have run command line related with adb with tcp port for fix issues long time ago.(I cannot remember what that command line is, I did google and run command line), I am assuming if that might be a problem.我记得很久以前我已经运行与带有 tcp 端口的adb相关的命令行来修复问题。(我不记得那个命令行是什么,我做了谷歌并运行命令行),我假设这可能是一个问题。
  • All of the problem files are exist in the same directory: app specific directory which is allocated by android.所有问题文件都存在于同一目录中:由 android 分配的应用程序特定目录。 I have read this android development documentation .我已阅读此android 开发文档 so what I think is First, react native request an image to android phone and Second, android phone have no access to the package folder, Third, so android phone could not get that image and return Network error: could not retrieve image file.所以我的想法是首先,向安卓手机反应原生请求图像,其次,安卓手机无法访问包文件夹,第三,所以安卓手机无法获取该图像并返回网络错误:无法检索图像文件。
  • Android phone has no permission to access the react native package directory so could not find the pdf file in file manager. Android 手机无权访问 react native 包目录,所以在文件管理器中找不到 pdf 文件。

Actual codes实际代码

  • AndroidMainfest.xml 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 (this is for android 11: this also copied from github issues forum) 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>

I think this is related to Android and local pc device.我认为这与 Android 和本地 pc 设备有关。 it would be nice if you can let us know about your development environment如果您能告诉我们您的开发环境,那就太好了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM