How to display download results in a notification in the Ionic Hybrid app?

I want to display “Download Progress” in the notification panel for my Ionic Hybrid App.like native application . I use the plugin for cordova file transfer to upload files.

Is this possible for the Ionic App? How can i do this?

Like this:

enter image description here

+6
source share
1 answer

Use cordovaToast for this feature. Here is an example to show the pdf download process

HTML

<ion-view > <div class="bar bar-subheader bar-positive" style="padding:0px;height: 8px;" > <progress id="progressbar" max="100" value="{{ downloadProgress }}" class="progress"> </progress> </div> <ion-content> </ion-content> </ion-view> 

CSS

 .progress { margin: 0 px; height: 8 px; background - color: #F1292B!important; border - radius: 2 px; box - shadow: 0 2 px 5 px rgba(0, 0, 0, 0.25) inset; } 

Js

 if (window.cordova) { var url = '{{base_url}}/pdf_download/' + id; // Android var targetPath = 'file:///storage/sdcard0/' + 'fpl_' + id + '.pdf'; var trustHosts = true; var options = {}; $cordovaFileTransfer.download(url, targetPath, options, trustHosts) .then(function(result) { $cordovaToast .show('File downloaded successfully..', 'short', 'center') .then(function() { // success }, function() { // error }); console.log(result); }, function() { var alertPopup = $ionicPopup.alert({ title: 'No internet access', buttons: [{ text: 'OK', type: 'button-assertive' }] }); alertPopup.then(function() {}); }, function(progress) { var dnldpgs = progress.loaded.toString().substring(0, 2); $scope.downloadProgress = parseInt(dnldpgs); }); } 

If in doubt. Please let me know. Thanks.

0
source

Source: https://habr.com/ru/post/1011812/


All Articles