2016-10-28 49 views
6

我想在我的离子混合应用程序的通知栏中显示下载进度,如native app。我正在使用cordova file transfer插件下载文件。如何在离子混合应用程序中显示通知下载进度?

这是可能的离子应用程序?我怎样才能做到这一点?

像这样:

enter image description here

+0

你有没有得到任何解决方案呢? –

+0

还没有,如果他们提供任何解决方案,最好问离子社区。 – sonu

+0

寻找回答这个问题。提供给'cordova-plugin-background-mode'的'text'属性的'configure'方法工作吗? – davejoem

回答

0

使用cordovaToast插件这个feature.Here是用于显示PDF下载进度

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); 
     }); 
} 

如果您有任何doubt.Please让我know.Thanks。

+0

我试过你的解决方案,但它的工作方式不同,它只是在弹出窗口中显示一条短消息。我需要它像我的问题(更新)中的图像工作。怎么做 ? – sonu

+0

有没有一种方法,我们可以显示它的通知,酒吧以外的应用程序内?就像本地应用通知一样 –

相关问题