无法在Android和解决方案中搜索APP特定文件的原因
我正在构建一个React Native应用程序,其中包括 pdf文件下载和图像上传功能。
要进行文件下载,我正在使用 react-native-fs 和 react-native-html-to-pdf ,并且在图像上传中,我正在使用 axios 和反应形象 - 图像杂音picker 。
我已经在很久以前就实现了 image上传功能,它就像魅力一样工作。
如今,我已经实现了 pdf文件下载功能,并且效果很好。
问题
- 图像上传不再起作用。
错误消息由React-nog log-android
如下所示: 网络错误
_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存在于App特定文件夹中,但在Android文件中不可发现 经理。
下载pdf文件路径就是这样:/storage/emulaty/0/android/data/packagename/files/files/data/data/user/0/packagename/files/files/filename.pdf
,我绝对检查了这是存在于确切目录中。
- 其他应用程序(APK)特定文件可以在Android文件管理器中发现。
我想知道的是
- 为什么只有我的React Native Package Directory无法在文件管理器中发现,甚至其他特定于应用程序的文件也无法发现?
- 我错过或完成的哪个设置不正确?
我为测试图像上传所做的工作
- 这个功能效果很好,因此我从Github下载了旧的订单版本并重建了所有应用程序。并试图上传图像,但出现了同样的问题。
我认为的是
- 我记得我已经运行了与 adb 与TCP端口有关的命令行,以解决问题。(我不记得那条命令行是什么,我Google和运行命令行是否),我假设这是否可能是问题。
- 所有问题文件都存在于同一目录中:由Android分配的APP特定目录。我已经阅读了此 android开发文档。 因此,我认为首先是React Antive请求图像到Android手机,其次,Android手机无法访问包装文件夹,第三,因此Android手机无法获取该图像并返回网络错误:无法检索图像文件。
- Android Phone无权访问React本地软件包目录,因此在文件管理器中找不到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 \ src \ main \ res \ res \ xml \ filepaths.xml (这是针对Android 11:也从Github问题复制了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 am building a react native app which includes pdf file download and image upload functionality.
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.
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.
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',
- Downloaded pdf file is exist in app-specific folder but not discoverable in Android file manager.
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.
- Other apps(apks) specific files are discoverable in Android file manager.
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?
- 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. 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.
- All of the problem files are exist in the same directory: app specific directory which is allocated by android. I have read this android development documentation.
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.
Actual codes
- 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)
<?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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这与Android和本地PC设备有关。
如果您能让我们知道您的开发环境,那就太好了
I think this is related to Android and local pc device.
it would be nice if you can let us know about your development environment