简体   繁体   English

Angular2 Ionic2使用Cordova创建插件

[英]Angular2 Ionic2 create plugin with cordova

I have created an angular 2 application with typescript and i have packaged it on an android apk and it works pretty well. 我用打字稿创建了一个angular 2应用程序,并将其打包在android apk上,并且效果很好。

But i have an issue, i wish to create a plugin for ionic 2 with cordova because i didn't find a plugin that does what i want to do. 但是我有一个问题,我希望使用cordova为ionic 2创建一个插件,因为我没有找到可以满足我需求的插件。

I downloaded plugman, created a new plugin but i have no idea how to make it works with my ionic application , i didn't find any tutorial on the subject just about cordova. 我下载了plugman,创建了一个新插件,但是我不知道如何使其与我的离子应用程序兼容,我没有找到关于cordova的任何教程。

I have the plugin directory with a java file where i am supposed to implement my methods, the plugin.js that allows to send request to the native part but how to connect this javascript to my angular2/ionic2 application ? 我有一个带有Java文件的插件目录,应该在其中实现我的方法,plugin.js允许向本地部分发送请求,但是如何将此JavaScript连接到我的angular2 / ionic2应用程序? How to call it ? 怎么称呼它?

Thanks everyone ! 感谢大家 !

I think this tutorial will help you. 我认为本教程将为您提供帮助。

My examples, i copy the WavAudioEncoder.min.js library into my www folder, then i do the followings, it works well (as you can see on the tutorial link too) 以我的示例为例,我将WavAudioEncoder.min.js库复制到我的www文件夹中,然后执行以下操作,它运行良好(您也可以在教程链接上看到)

declare var WavAudioEncoder: any;

var encoder = new WavAudioEncoder(this.captureCfg.sampleRate, this.captureCfg.channels);

Do not panic if the environment won't suggest you anything, when you use these plugins/libraries (eg in VSCode the cordova.file is not a function, it will say to you it is a simple variable which type is any ) 使用这些插件/库时,如果环境对您无济于事, 不要惊慌(例如,在VSCode中, cordova.file不是函数,它将告诉您这是一个简单的变量,类型为any

declare var cordova: any;
this.filePath = cordova.file.externalDataDirectory;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM