flutter_downloader icon indicating copy to clipboard operation
flutter_downloader copied to clipboard

problem open loaded task

Open adham-ashraf77 opened this issue 1 year ago • 17 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 ?

adham-ashraf77 avatar Jan 11 '24 09:01 adham-ashraf77

https://github.com/fluttercommunity/flutter_downloader/assets/55947445/69a26f92-a7d4-419d-a9ff-eecece2458b3

adham-ashraf77 avatar Jan 11 '24 10:01 adham-ashraf77

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

salmaahhmed avatar Jan 11 '24 12:01 salmaahhmed

Thank you need it urgently please

adham-ashraf77 avatar Jan 11 '24 12:01 adham-ashraf77

Is there any news, please? @salmaahhmed

adham-ashraf77 avatar Jan 14 '24 09:01 adham-ashraf77

Same thing happening to me on version 1.10.5

morenojulio avatar Jan 18 '24 22:01 morenojulio

Is there any news, please? @salmaahhmed

adham-ashraf77 avatar Jan 23 '24 07:01 adham-ashraf77

any news @salmaahhmed ?

adham-ashraf77 avatar Feb 12 '24 18:02 adham-ashraf77

@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.

balajiks-dev avatar Feb 14 '24 03:02 balajiks-dev

any news @salmaahhmed ?

Mahmoudagha01 avatar Feb 22 '24 18:02 Mahmoudagha01

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

balajiks-dev avatar Mar 05 '24 06:03 balajiks-dev

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

adham-ashraf77 avatar Mar 05 '24 07:03 adham-ashraf77

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

balajiks-dev avatar Mar 05 '24 07:03 balajiks-dev

@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 avatar Mar 05 '24 08:03 adham-ashraf77

@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

balajiks-dev avatar Mar 05 '24 08:03 balajiks-dev

@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.)

balajiks-dev avatar Mar 05 '24 08:03 balajiks-dev