【问题标题】:Ionic get installed apps on android device with iconIonic 在带有图标的 android 设备上安装应用程序
【发布时间】:2018-06-24 08:43:20
【问题描述】:

我知道这个问题已经被问过了,但我在那个解决方案中遇到了问题,那里没有回答。

我使用了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'

【问题讨论】:

  • 如果您参考已经问过这个问题的地方可能会有所帮助
  • Typescript 编译器无法识别 AppList 的来源。尝试在文件顶部添加import { Applist } from 'cordova-plugin-applist/www/Applist.js';
  • 我做了然后它显示错误无法读取未定义的属性'createEvent'
  • 我的错,改成import * as Applist from 'cordova-plugin-applist/www/Applist.js';

标签: android angular cordova ionic-framework


【解决方案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);
      }
    }
  );
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-11
  • 2011-06-05
  • 2017-08-27
  • 2011-08-27
相关资源
最近更新 更多