打开studio在左侧列表中找到config.xml文件,双击打开,选择插件选项勾选cordova-plugin-dialogs文件,并在权限选项中选择相关权限。最后保存文件。

引用该插件主要是为了判断是否有网络连接和网络连接的类型。

  1. function checkConnection() {
  2. var networkState = navigator.connection.type;
  3. var states = {};
  4. states[Connection.UNKNOWN] = 'Unknown connection';
  5. states[Connection.ETHERNET] = 'Ethernet connection';
  6. states[Connection.WIFI] = 'WiFi connection';
  7. states[Connection.CELL_2G] = 'Cell 2G connection';
  8. states[Connection.CELL_3G] = 'Cell 3G connection';
  9. states[Connection.CELL_4G] = 'Cell 4G connection';
  10. states[Connection.CELL] = 'Cell generic connection';
  11. states[Connection.NONE] = 'No network connection';
  12. alert('Connection type: ' + states[networkState]);
  13. }

用例github下载地

文档更新时间: 2018-01-15 14:14