Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem open loaded task #931

Open
adham-ashraf77 opened this issue Jan 11, 2024 · 15 comments
Open

problem open loaded task #931

adham-ashraf77 opened this issue Jan 11, 2024 · 15 comments
Labels
bug Something isn't working

Comments

@adham-ashraf77
Copy link

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 adham-ashraf77 added the bug Something isn't working label Jan 11, 2024
@adham-ashraf77
Copy link
Author

Recording.2024-01-11.121259.mp4

@salmaahhmed
Copy link
Collaborator

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

@adham-ashraf77
Copy link
Author

Thank you need it urgently please

@adham-ashraf77
Copy link
Author

Is there any news, please? @salmaahhmed

@morenojulio
Copy link

Same thing happening to me on version 1.10.5

@adham-ashraf77
Copy link
Author

Is there any news, please? @salmaahhmed

@adham-ashraf77
Copy link
Author

any news @salmaahhmed ?

@balajiks-dev
Copy link

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

@Mahmoudagha01
Copy link

any news @salmaahhmed ?

@balajiks-dev
Copy link

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

@adham-ashraf77
Copy link
Author

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

@balajiks-dev
Copy link

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

@adham-ashraf77
Copy link
Author

@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

@balajiks-dev
Copy link

balajiks-dev commented Mar 5, 2024

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants