当前位置: 首页 > 知识库问答 >
问题:

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

诸葛雨泽
2023-03-14

我正在构建一个react原生应用程序,其中包括pdf文件下载和图像上传功能。

对于文件下载,我使用的是react-native-fs和react-native-html-to-pdf,对于图像上传,我使用的是axios和react-native-image-crap-picker。

我很久以前就已经实现了图像上传功能,它很有魅力。

这几天,我已经实现了pdf文件下载功能,而且效果很好。

问题

  • 图像上传不再有效

由react native log android记录的错误消息如下所示:网络错误:无法检索uri/storage/emulated/0/android/data/packageName/files/Pictures/75a08b1a-98de-4811-8b44-453f6f2f9bf8的文件。jpg’,

  • 下载的pdf文件存在于应用程序特定的文件夹中,但在Android file manager中无法发现

下载pdf文件路径如下:/storage/emulated/0/Android/data/packageName/files/data/user/0/packageName/files/fileName。pdf,我已经检查过了,这肯定存在于确切的目录中。

  • 其他特定于应用程序(APK)的文件可以在Android file manager中找到

我想知道的是

  • 为什么只有我的react本机软件包目录无法在file manager中发现,而其他特定于应用程序的文件也可以发现
  • 我错过了哪个设置或做了哪些不正确的设置

我为测试图像上传做了什么

  • 此功能运行良好,因此我从Github下载了旧的提交版本并重建了所有应用程序。并尝试上传图像,但出现了同样的问题。

我假设的是

  • 我记得很久以前我用tcp端口运行与adb相关的命令行来修复问题。(我不记得那个命令行是什么,我用谷歌搜索并运行了命令行),我假设这可能是个问题
  • 所有问题文件都存在于同一个目录中:android分配的应用程序特定目录。我已经阅读了这个android开发文档。所以我认为首先,android手机无法访问软件包文件夹,第二,android手机无法获取该图像并返回网络错误:无法检索图像文件
  • Android phone无权访问react native package目录,因此无法在file manager中找到pdf文件

实际代码

  • Androidainfest.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\filepath。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>

共有1个答案

祝俊雄
2023-03-14

我认为这与Android和本地pc设备有关。如果您能让我们知道您的开发环境,那就太好了

 类似资料:
  • 本文向大家介绍centos下file_put_contents()无法写入文件的原因及解决方法,包括了centos下file_put_contents()无法写入文件的原因及解决方法的使用技巧和注意事项,需要的朋友参考一下 centos下file_put_contents()无法写入文件的原因是没有文件夹权限 直接修改目标文件夹/文件 # chmod 777 文件夹名称 以上这篇centos下fi

  • 问题内容: 我可以使用一个ResultSet方法搜索一个ResultSet并检查它是否具有特定的值/元素吗? 与方法类似。 如果没有,则无需键入搜索方法,我将做一个:) 提前致谢。 问题答案: 不要在Java端进行搜索。这不必要地很慢,并且占用内存。您基本上是在接手数据库的设计工作。只需让DB完成它设计的工作即可:借助SQL语言的强大功能,选择并返回所需的数据。 开始学习SQL子句。例如,要检查用

  • 本文向大家介绍Java String.replace()方法"无效"的原因及解决方式,包括了Java String.replace()方法"无效"的原因及解决方式的使用技巧和注意事项,需要的朋友参考一下 首先我们来看个例子 运行结果是什么呢?我们先看看这个方法的api 返回一个新的字符串,用newChar替换此字符串中出现的所有oldChar 所以这里的结果为:输出结果是abcd 而不是fbcd,

  • 谁能帮我一下吗。 我面临一个问题-Android应用程序Listview不能滚动到底部搜索特定元素使用appium在java > 使用的代码是: //元素是Listview //tvProvidername是滚动列表视图时要搜索的文本 谢谢,NRM

  • 本文向大家介绍Spring Boot应用上传文件时报错的原因及解决方案,包括了Spring Boot应用上传文件时报错的原因及解决方案的使用技巧和注意事项,需要的朋友参考一下 问题描述 Spring Boot应用(使用默认的嵌入式Tomcat)在上传文件时,偶尔会出现上传失败的情况,后台报错日志信息如下:“The temporary upload location is not valid”。 原

  • 本文向大家介绍解决Android平台中应用程序OOM异常的方法,包括了解决Android平台中应用程序OOM异常的方法的使用技巧和注意事项,需要的朋友参考一下 在Android平台上面,应用程序OOM异常永远都是值得关注的问题。通常这一块也是程序这中的重点之一。这下我就如何解决OOM作一点简单的介绍。 首先,OOM就是内存溢出,即Out Of Memory。也就是说内存占有量超过了VM所分配的最大