Ionic带有图标在Android设备上获取已安装的应用程序

时间:2018-06-24 08:43:20

标签: android angular cordova ionic-framework

我知道这个问题已经被提出了,但是我在那个解决方案中有问题,那里没有答案。

我使用了this插件,但这给了我错误:

var success = function (app_list) { alert(JSON.stringify(app_list)); };
var error = function (app_list) { alert("Oopsie! " + app_list); };
Applist.createEvent('', '', '', '', '', success, error)

如何清除此错误?我正在运行下载它:

npm i cordova-plugin-applist

错误消息:

Cannot find name 'Applist'

1 个答案:

答案 0 :(得分:1)

添加

import * as Applist from 'cordova-plugin-applist2/www/Applist.js';
import { Platform } from '@ionic/angular';

到您的组件.ts文件

然后在可能的构造函数中使用它

constructor(public platform: Platform) {
  platform.ready().then(
    function(){
      if(platform.is('android') && !platform.is('mobileweb')){
          var success = function(app_list) { 
            //success function
            console.log(app_list);
           };
          var error = function(app_list) {  
            //error          
            console.log("An Error occured while fetching App Lists");
            console.error(app_list);
          };
          //for the date parameters, any date is okay, 
          //the first date should be in the past
          Applist.createEvent('', '', '', new Date(1999, 10, 11, 12, 12, 12, 12), new Date(), success, error);
      }
    }
  );
}