2

I have an app, and I need to choose files like PDF JSON, etc. First, I export my file, and then I can import it. To do this, I use the file_picker package with the below codes. Now the question is, I can pick any file's path in iOS, but on the Android side, I can not select the file or file path directly, even though I give permission in the AndroidManifest.

in iOS, when I trigger pickFile() function from the file_picker, it works as well. In the Android section, when I trigger the function, it opens the files, but I can not select the path or file directly. Even I can not see Flutter's application folder.

Here are the codes that I use:

 final result = await FilePicker.platform.pickFiles(
                type: FileType.custom,
                allowedExtensions: ['json'],
              );

Here, after getting the result I check the other conditions. Right now problem is, as I said, I can not get the file/file path from the android side specifically.

Android Manifest section:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />
alperefesahin
  • 604
  • 6
  • 22
  • `Right now problem is, as I said, I can not get the file/file path from the android side specifically.` Pretty unclear what your problem is. Are you saying that the user can not select a file? – blackapps Apr 19 '23 at 08:53
  • `Here, after getting the result` Well what kind of result do you get? Please tell specific value. – blackapps Apr 19 '23 at 08:55
  • Sorry to hear this. Actually, the result is the selected file, and it works as well in iOS. On the other hand, since a user can not select a file in Android, I can not move further with the result variable. – alperefesahin Apr 19 '23 at 12:14

1 Answers1

1

To limit broad access to shared storage, target Android 11 (API level 30) or higher, request all-files access through the MANAGE_EXTERNAL_STORAGE permission.

To do that after adding WRITE_EXTERNAL_STORAGE to AndroidManifest.xml, add permission_handler package to your apps and Request permission like:

 void requestPermission() {  

await Permission.manageExternalStorage.request();
  
  }
A. Rokbi
  • 503
  • 2
  • 8