skip to Main Content

I am using the flutter file picker 6.0.0.When i try to select file from the picker file.I used singleInstance in manifest.

 FilePickerResult? result = await FilePicker.platform.pickFiles(allowedExtensions: ['jpg','jpeg','png','pdf'],type: FileType.custom);
if (result != null) {
  File file = File(result.files.single.path!);
  controller.isPasswordProtected.value =
      await FileHelper.checkFileIsPasswordProtected(file);
  controller.fileSelected(file);
  controller.uploadDocument();
}

2

Answers


  1. It seems like you’re using the Flutter File Picker plugin and encountering an issue on Android. However, you haven’t specified the exact problem you’re facing. From your code snippet, it appears that you’re attempting to pick files with specific extensions (jpg, jpeg, png, pdf) and then perform some actions with the selected file.

    If you’re experiencing difficulties running this code on Android, here are a few considerations and potential troubleshooting steps:

    1.Permissions: Ensure that you have the necessary permissions declared in your AndroidManifest.xml file. Depending on the Android version, you might need to request runtime permissions for file access.

    2.File Provider: If you’re dealing with files in your app, especially for newer Android versions (Android 10 and above), you might need to use a File Provider to grant access to the files. This involves setting up the necessary configurations in your AndroidManifest.xml and a file_paths.xml file.

    3.Handling URI: Android has specific ways of handling URIs, especially concerning file access. If you’re using the file path directly, you might need to consider using a content URI or file URI based on Android’s version and restrictions.

    4.Handling External Storage: If you’re accessing files from external storage, make sure your app has permission to read from external storage by requesting the READ_EXTERNAL_STORAGE permission.

    5.File URI Scheme: Android 11 and later restrict access to files outside your app’s sandbox by default. Ensure you are using the appropriate URI scheme (content://, file://) based on the file’s location.

    To help you more specifically, could you provide additional details about the issue you’re facing on Android while using the file picker? Errors, unexpected behaviors, or specific scenarios where the code fails would be helpful for a more targeted solution.

    Login or Signup to reply.
  2. It looks like this is expected behavior on Android, you can see here. If the calling app forbids other activities in its task, then it can’t get results from other activities.

    Related flutter plugin image_picker is also mentioning about singleInstance launch mode :

    Launching the image picker from an Activity with launchMode: singleInstance will always return RESULT_CANCELED. In this launch mode, new activities are created in a separate Task. As activities cannot communicate between tasks, the image picker activity cannot send back its eventual result to the calling activity. To work around this problem, consider using launchMode: singleTask instead.

    Read the details here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search