How to download file natively?

Hello everyone.
I’m trying to download files using the fileTrasnfer plugin, it usually downloads but only works when the app is active, I wonder if there is any way to make the download start as if it were native.
Does anyone have any ideas?

write your own plugin for that in the worstcase scenario
That way you could do everything you want.

are you on ios or on android?

Initially on Android, I forgot to warn you, I’m using ionic 3

When do you want to start you download? what are you downloading?

I am downloading from the click of a button, the downloaded file is audio.

I think that is what you mean: https://developer.android.com/reference/android/app/DownloadManager.html

that looks like an plugin for that https://github.com/emilbayes/cordova-plugin-android-downloadmanager or you could write your own for max. customizability.

And please be aware that you need another solution for iOS when you want to expand your app to apples devices in the future.

It seems that this plugin does not work in 3

whats the exact problem? (it was the newest that I found via a quick google search)

Maybe it’s my lack of experience, download the plugin normally, but I’m not sure how to import the plugin into the project

I’ll try it for my self… brb

what kind of audio? musik or podcast?

Audio of the type mp3 music

my little test app that works, you have to configure it to your needs (mimetype, uri),

  • using __proto__ is definitly not the best solution, but it works.
  • callback is not in a array as he described on his readme github page.
  • ionic cordova plugin add cordova-plugin-android-downloadmanager to install it
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import * as dl from 'cordova-plugin-android-downloadmanager';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController) {

    let req = {
  uri: 'http://ipv4.download.thinkbroadband.com/100MB.zip',
  title: 'Testfile',
  description: 'a test file',
  mimeType: 'application/zip',

  visibleInDownloadsUi: true,
  notificationVisibility: 0,

  // Either of the next three properties
  destinationInExternalFilesDir: {
    dirType: 'DIRECTORY_MUSIC',
    subPath: ''
  }
};
  console.log(dl);
  let dl2= dl.__proto__;
  console.log(dl2);
    dl2.enqueue(req, console.info);
  }

}

I was able to import the plugin as you taught me, the download does not start, I’m trying this way:

let req = {
         uri: 'https://www.colorado.edu/conflict/peace/download/peace.zip',
         title: 'Testfile',
         description: 'a test file',
         mimeType: 'application / zip',      
         visibleInDownloadsUi: true,
         notificationVisibility: 1,
      
         // Either of the next three properties
         destinationInExternalFilesDir: {
           dirType: this.file.externalRootDirectory,
           subPath: '/ Download /'
         }
       };
         console.log (dl);
         let dl2 = dl .__ proto__;
         console.log (dl2);
           dl2.enqueue (req, console.log);

It looks like the error is this: Error: exec proxy not found for :: DownloadManagerPlugin :: enqueue
The method is called but the download does not start, am I doing something wrong?

are you testing it on a real device or an emulator or with ionic serve?

I’m testing on a real device

that’s weird, it worked on my oneplus 3.
but i first installed the plugin via npm and then with again with cordova plugin add, maybe that would make any difference?
I also used a new blank project for that.
Your error seems to have sth. to do with cordova, maybe you should try to investigate in that direction or write your own plugin with that plugin as reference.
Good luck.

maybe call it after a device ready event.

@user5555 @LeoFeitosa

Can anyone please tell me how to change downloaded file path, because I have tried with below code.

 destinationInExternalFilesDir: {
    dirType: this.file.externalRootDirectory,
    subPath: '/Download/'
}  

But downloaded file is always falling in the below path.

/Internal Storage/Android/data/io.ionic.starter/files/ this path is always there for downloaded file. Is there any way to download file in “Download” folder?