$cordovaNetwork 使用
1 .安装插件
直接安装:
cordova plugin add cordova-plugin-network-information
下载到本地安装:
https://github.com/apache/cordova-plugin-network-information
2.代码使用
.controller('ContentCtrl', function ($scope, $stateParams, $ionicLoading,ENV,$cordovaNetwork,$ionicPopup) {
$scope.playVideo= function (videosrc) {
var type = $cordovaNetwork.getNetwork();
if(type==Connection.WIFI){
if(videosrc!=""){
VideoPlayer.play(ENV.imgUrl+videosrc);
}
}
else{
$scope.showConfirm = function() {
var confirmPopup = $ionicPopup.confirm({
title: '播放提示',
template: '现在不在WiFi环境下,是否使用4G流量进行播放!'
});
confirmPopup.then(function(res) {
if(res) {
if(videosrc!=""){
VideoPlayer.play(ENV.imgUrl+videosrc);
}
}
});
};
}
}
})
3.其它
// 监听手机网络在线事件
$rootScope.$on('$cordovaNetwork:online', function(event, networkState){
var onlineState = networkState;
})
// 监听手机网络离线事件
$rootScope.$on('$cordovaNetwork:offline', function(event, networkState){
var offlineState = networkState;
})
var type = $cordovaNetwork.getNetwork();
type 类型:
Connection.UNKNOWN
Connection.ETHERNET
Connection.WIFI WiFi
Connection.CELL_2G
Connection.CELL_3G
Connection.CELL_4G
Connection.CELL
Connection.NONE
以上方法一般在run 的$ionicPlatform.ready 里面处理
随机推荐
- IENumerable_Test
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using S ...
- reboot与shutdown -r now 区别与联系(又收集了init和halt的小知识)
在linux命令中reboot是重新启动,shutdown -r now是立即停止然后重新启动,都说他们两个是一样的,其实是有一定的区别的. shutdown命令可以安全地关闭或重启Linux系统,它 ...
- ERROR 1839 (HY000): @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_MODE = ON
从cdb上dump一个库结构,准备与本地结构做对比(可以直接compare,但速度贼慢).使用dump脚本在本地创建的时候报错 -- 导出指定库的结构 shell> mysqldump -hxx ...
- <转>http协议 文件下载原理详解
最近研究了一下关于文件下载的相关内容,觉得还是写些东西记下来比较好.起初只是想研究研究,但后来发现写个可重用性比较高的模块还是很有必要的,我想这也是大多数开发人员的习惯吧. 对于HTTP协议,向服务器 ...
- 创建 linuxrc 文件
创建 linuxrc,加入如下内容: [arm@localhost my_rootfs]#vi linuxrc #!/bin/sh #挂载/etc 为 ramfs, 并从/mnt/etc 下拷贝文件到 ...
- MQTT入门介绍
一简述 MQTT(Message Queuing Telemetry Transport,消息队列遥测传输协议),是一种基于发布/订阅(publish/subscribe)模式的"轻量级&q ...
- leetcode-105-从前序与中序遍历构造二叉树
题目描述: 方法一: # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.va ...
- PHPstorm同步服务器代码的缺点---命名空间undefined
在把一个服务器的代码同步到phpstorm下开发的时候,发现新建的命名空间代码都失效了,然而换到 https://blog.csdn.net/afraid_to_have/article/deta ...
- Spring中的Junit
Spring中的Junit package com.imooc.test.base; import org.junit.After; import org.junit.Before; import o ...
- 2016年深圳市服务业占GDP比重首次突破六成
2016年深圳市服务业占GDP比重首次突破六成 中商产业研究院 中商情报网 2017-01-12 11:08 分享: 中商情报网讯 1月10日,深圳市财政委员会召开新闻发布会,就深圳市2016 ...