如何实现Android的cordova-plugin-datepicker?

时间:2022-08-02 14:29:26

I have tried to implement this Datetimepicker ( https://github.com/VitaliiBlagodir/cordova-plugin-datepicker ) but still not working on my Android Device ( Android 4.0.4).

我试图实现这个Datetimepicker(https://github.com/VitaliiBlagodir/cordova-plugin-datepicker),但仍然无法在我的Android设备上运行(Android 4.0.4)。

  1. I added the plugin to my Project and used : cordova plugin add https://github.com/VitaliiBlagodir/cordova-plugin-datepicker.

    我将插件添加到我的项目并使用:cordova插件添加https://github.com/VitaliiBlagodir/cordova-plugin-datepicker。

  2. Put a Trigger to my js file and tried to test a alert("test"). I get the test alert on browser and on Device, but no alert from Datetimepicker?

    将触发器放入我的js文件并尝试测试警报(“测试”)。我在浏览器和设备上收到测试警报,但没有来自Datetimepicker的警报?

  3. I also rm Android from Platform and build it again, everything is there, but still not working. ( To build the app, i am using PhoneGap Build)

    我也从平台安装Android并再次构建它,一切都在那里,但仍然无法正常工作。 (要构建应用程序,我正在使用PhoneGap Build)

  4. I have no idea what I am missing? .... any help would be nice :-).

    我不知道我错过了什么? .... 你能帮忙的话,我会很高兴 :-)。


Example:

in Html

<input type="text"  onclick="calendar()" />

in JS

<script>

function calendar(){

  alert("test")  //  is working

  var options = {
    date: new Date(),
    mode: 'date'
  };

  datePicker.show(options, function(date){
   alert("date result " + date);     // not working
  });

}

</script>

4 个解决方案

#1


You don't have to add the script in your path.

您不必在路径中添加脚本。

Make sur you have register the plugin to your config.xml like so :

制作你已经将插件注册到你的config.xml,如下所示:

<feature name="DatePicker">
  <param name="ios-package" value="DatePicker"/>
</feature>

<feature name="DatePickerPlugin">
  <param name="android-package" value="com.okaybmd.cordova.plugin.datepicker.DatePickerPlugin"/>
</feature>

(more info @ http://phonegap-plugins.com/plugins/okaybmd/cordova-plugin-datepicker )

(更多信息@ http://phonegap-plugins.com/plugins/okaybmd/cordova-plugin-datepicker)

The plugin won't work in your browser. You have to test it through your device or an emulator.

该插件无法在您的浏览器中使用。您必须通过您的设备或模拟器进行测试。

#2


Did you include your script in your HTML ?

您是否在HTML中包含了脚本?

<script src="your/path/DatePicker.js"></script>

#3


The datepicker returns a promise, so you need to handle that on your code.

datepicker返回一个promise,因此你需要在你的代码上处理它。

<script>

function calendar(){

  alert("test")  //  is working

  var options = {
    date: new Date(),
    mode: 'date'
  };

  datePicker.show(options).then(function(date){
   alert("date result " + date);
  });

}

</script>

Also, I have always used this with Angular, so not completely sure on how you inject the service for your usage.

此外,我一直使用Angular,因此不完全确定如何为您的使用注入服务。

Reference: http://ngcordova.com/docs/plugins/datePicker/

#4


I used it for developing and Ionic app. The idea was to simply add the plugin (datepicker) and include ngCordova and ngCordovaMocks js files in your resources and the HTML.

我用它来开发和离子应用程序。我们的想法是简单地添加插件(datepicker)并在您的资源和HTML中包含ngCordova和ngCordovaMocks js文件。

ngCordovaMocks is for web development.

ngCordovaMocks用于Web开发。

The injection was done while building apk or ipa at the main module

注入是在主模块上构建apk或ipa时完成的

app.module('asas',['ngCordova'],function($cordovaDatePicker){

}).run()

#1


You don't have to add the script in your path.

您不必在路径中添加脚本。

Make sur you have register the plugin to your config.xml like so :

制作你已经将插件注册到你的config.xml,如下所示:

<feature name="DatePicker">
  <param name="ios-package" value="DatePicker"/>
</feature>

<feature name="DatePickerPlugin">
  <param name="android-package" value="com.okaybmd.cordova.plugin.datepicker.DatePickerPlugin"/>
</feature>

(more info @ http://phonegap-plugins.com/plugins/okaybmd/cordova-plugin-datepicker )

(更多信息@ http://phonegap-plugins.com/plugins/okaybmd/cordova-plugin-datepicker)

The plugin won't work in your browser. You have to test it through your device or an emulator.

该插件无法在您的浏览器中使用。您必须通过您的设备或模拟器进行测试。

#2


Did you include your script in your HTML ?

您是否在HTML中包含了脚本?

<script src="your/path/DatePicker.js"></script>

#3


The datepicker returns a promise, so you need to handle that on your code.

datepicker返回一个promise,因此你需要在你的代码上处理它。

<script>

function calendar(){

  alert("test")  //  is working

  var options = {
    date: new Date(),
    mode: 'date'
  };

  datePicker.show(options).then(function(date){
   alert("date result " + date);
  });

}

</script>

Also, I have always used this with Angular, so not completely sure on how you inject the service for your usage.

此外,我一直使用Angular,因此不完全确定如何为您的使用注入服务。

Reference: http://ngcordova.com/docs/plugins/datePicker/

#4


I used it for developing and Ionic app. The idea was to simply add the plugin (datepicker) and include ngCordova and ngCordovaMocks js files in your resources and the HTML.

我用它来开发和离子应用程序。我们的想法是简单地添加插件(datepicker)并在您的资源和HTML中包含ngCordova和ngCordovaMocks js文件。

ngCordovaMocks is for web development.

ngCordovaMocks用于Web开发。

The injection was done while building apk or ipa at the main module

注入是在主模块上构建apk或ipa时完成的

app.module('asas',['ngCordova'],function($cordovaDatePicker){

}).run()