fluttercommunity/flutter_downloader

problem open loaded task

adham-ashraf77 opened this issue · 15 comments

await FlutterDownloader.open(taskId: item.taskId);

open the pdf then close it what is the problem android 14 api 34 and any Android version the open function works fine with ios can you help me please ?

Recording.2024-01-11.121259.mp4

@adham-ashraf77 thanks for reporting the issue. i will take a look now.

Thank you need it urgently please

Is there any news, please? @salmaahhmed

Same thing happening to me on version 1.10.5

Is there any news, please? @salmaahhmed

@salmaahhmed If you are not working in the bug, let us know. People are keep waiting for your response which is unfair. Please keep posted for any status update either positive or negative.

@adham-ashraf77 Can you please check the status of file download and progress of file download.

@balajiks-dev the download works well no problem but the problem if I open the downloaded file like the video send above

@adham-ashraf77 Please add example code to reproduce this issue.

@balajiks-dev

void _requestDownload(String link, BuildContext context,
ShipingOrderDetails shipingOrderDetails) async {
try {
var item = loaded!.firstWhere((element) => element.url == link);

  bool test = await FlutterDownloader.open(taskId: item.taskId);

  print("**************");
  print(test);
  print("**************");
  // if (test == false) {
  //   throw Exception();
  // }
} catch (e) {
  if (await confirm(
    context,
    title: Text(LocaleKeys.doYouWantToPrintOrderDetails.tr()),
    content: const SizedBox(),
    textOK: Text(
      LocaleKeys.yes.tr(),
      style: AppTextStyles.medium14BlackTextStyle,
    ),
    textCancel: Text(
      LocaleKeys.no.tr(),
      style: AppTextStyles.medium14BlackTextStyle,
    ),
  )) {
    final baseStorage = Platform.isAndroid
        ? await getExternalStorageDirectory() //FOR ANDROID
        : await getApplicationDocumentsDirectory();
    var status = await Permission.storage.request();
    var status2 = await Permission.manageExternalStorage.request();
    log(status.toString());
    if (status.isGranted || status2.isGranted) {
      final taskId = await FlutterDownloader.enqueue(
        fileName: '${shipingOrderDetails.number}.pdf',
        url: link,
        savedDir: baseStorage!.absolute.path,
        allowCellular: true,
        saveInPublicStorage: true,
        headers: {
          AppStrings.authorization:
              '${AppStrings.bearer} ${di.sl<SharedPreferences>().getString(AppStrings.token)}'
        },
        showNotification: true,
        // show download progress in status bar (for Android)
        openFileFromNotification:
            true, // click on notification to open downloaded file (for Android)
      );
      log(taskId.toString());
      //share file
      await Share.shareXFiles(
        [XFile('${baseStorage.path}/${shipingOrderDetails.number}.pdf')],
      );
      loaded = await FlutterDownloader.loadTasks();
    }
  }
  // We didn't ask for permission yet or the permission has been denied before but not permanently.
}

}

note the code works fine with ios no problems

@adham-ashraf77 Please open the file through open_filex once the file downloaded with the download file path.

OpenFilex.open(${file.path})');

Note: Don't forget to add the permission in Android manifest file

@adham-ashraf77

Kindly check these

To make tapping on notification open the downloaded file on Android, add the following code to AndroidManifest.xml:

<provider android:name="vn.hunghd.flutterdownloader.DownloadedFileProvider" android:authorities="${applicationId}.flutter_downloader.provider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/> </provider>

Notes

You have to save your downloaded files in external storage (where the other applications have permission to read your files)
The downloaded files are only able to be opened if your device has at least one application that can read these file types (mp3, pdf, etc.)