0

I am using ionic v4 and the ngx-qrcode library to generate a qrcode. However I also need to download this generated qrcode, but ionic does not perform any action when I click the button on android. In the browser works.

getImage(): void {
    const canvas = document.querySelector('canvas') as HTMLCanvasElement;

    const imageData = canvas.toDataURL('image/jpeg').toString();
    const img = document.createElement('img');
    img.src = imageData;

    const a = document.createElement('a');
    a.setAttribute('download', 'YourFileName.jpeg');
    a.setAttribute('href', imageData);
    a.appendChild(img);
    a.click();
  }

At the moment when I click the download button that is in html, it only works if I am in the browser, but in android nothing happens

Willian Ferreira
  • 341
  • 1
  • 2
  • 3

1 Answers1

0

You can't use a link with the download attribute, You need to use a file native plugin of cordova. I share this code:

import {File} from '@ionic-native/file/ngx';

save(){
  this.file.writeFile(this.file.applicationStorageDirectory, name, data)
    .then((entry)=>{
        console.log(entry);
    }).catch((err)=>{
        console.log(err);
  })
}

Here info about store file

Edward
  • 1
  • 1