mirror of
https://gitee.com/shuto/cordova-plugin-network-information.git
synced 2025-03-17 13:21:02 +08:00
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information
This commit is contained in:
commit
60838168a6
@ -1,3 +1,24 @@
|
|||||||
|
<!--
|
||||||
|
#
|
||||||
|
# Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
# or more contributor license agreements. See the NOTICE file
|
||||||
|
# distributed with this work for additional information
|
||||||
|
# regarding copyright ownership. The ASF licenses this file
|
||||||
|
# to you under the Apache License, Version 2.0 (the
|
||||||
|
# "License"); you may not use this file except in compliance
|
||||||
|
# with the License. You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing,
|
||||||
|
# software distributed under the License is distributed on an
|
||||||
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
# KIND, either express or implied. See the License for the
|
||||||
|
# specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
#
|
||||||
|
-->
|
||||||
|
|
||||||
# Contributing to Apache Cordova
|
# Contributing to Apache Cordova
|
||||||
|
|
||||||
Anyone can contribute to Cordova. And we need your contributions.
|
Anyone can contribute to Cordova. And we need your contributions.
|
||||||
|
3
NOTICE
3
NOTICE
@ -3,3 +3,6 @@ Copyright 2012 The Apache Software Foundation
|
|||||||
|
|
||||||
This product includes software developed at
|
This product includes software developed at
|
||||||
The Apache Software Foundation (http://www.apache.org/).
|
The Apache Software Foundation (http://www.apache.org/).
|
||||||
|
|
||||||
|
This product includes software developed by Apple Inc. License can be found in the header of the affected files. (src/ios/CDVReachability.h, src/ios/CDVReachability.m)
|
||||||
|
|
||||||
|
@ -53,3 +53,12 @@
|
|||||||
* CB-6460: Update license headers
|
* CB-6460: Update license headers
|
||||||
* CB-6465: Add license headers to Tizen code
|
* CB-6465: Add license headers to Tizen code
|
||||||
* Add NOTICE file
|
* Add NOTICE file
|
||||||
|
|
||||||
|
### 0.2.9 (Jun 05, 2014)
|
||||||
|
* updated notice file to include missing license
|
||||||
|
* Cached extra info to better detect changes.
|
||||||
|
* CB-6809 Add license to CONTRIBUTING.md
|
||||||
|
* CB-6491 add CONTRIBUTING.md
|
||||||
|
* CB-6350 - Fix networkStatusForFlags return value type to work with 64-bit iOS (closes #8)
|
||||||
|
* Initial version of firefox os network information plugin
|
||||||
|
* there was an error in the object definition
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
id="org.apache.cordova.network-information"
|
id="org.apache.cordova.network-information"
|
||||||
version="0.2.9-dev">
|
version="0.2.10-dev">
|
||||||
|
|
||||||
<name>Network Information</name>
|
<name>Network Information</name>
|
||||||
<description>Cordova Network Information Plugin</description>
|
<description>Cordova Network Information Plugin</description>
|
||||||
|
@ -24,6 +24,8 @@ import org.apache.cordova.CordovaPlugin;
|
|||||||
import org.apache.cordova.PluginResult;
|
import org.apache.cordova.PluginResult;
|
||||||
import org.apache.cordova.CordovaWebView;
|
import org.apache.cordova.CordovaWebView;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -75,7 +77,7 @@ public class NetworkManager extends CordovaPlugin {
|
|||||||
|
|
||||||
ConnectivityManager sockMan;
|
ConnectivityManager sockMan;
|
||||||
BroadcastReceiver receiver;
|
BroadcastReceiver receiver;
|
||||||
private String lastStatus = "";
|
private JSONObject lastInfo = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -126,7 +128,12 @@ public class NetworkManager extends CordovaPlugin {
|
|||||||
if (action.equals("getConnectionInfo")) {
|
if (action.equals("getConnectionInfo")) {
|
||||||
this.connectionCallbackContext = callbackContext;
|
this.connectionCallbackContext = callbackContext;
|
||||||
NetworkInfo info = sockMan.getActiveNetworkInfo();
|
NetworkInfo info = sockMan.getActiveNetworkInfo();
|
||||||
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, this.getConnectionInfo(info));
|
String connectionType = "";
|
||||||
|
try {
|
||||||
|
connectionType = this.getConnectionInfo(info).get("type").toString();
|
||||||
|
} catch (JSONException e) { }
|
||||||
|
|
||||||
|
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, connectionType);
|
||||||
pluginResult.setKeepCallback(true);
|
pluginResult.setKeepCallback(true);
|
||||||
callbackContext.sendPluginResult(pluginResult);
|
callbackContext.sendPluginResult(pluginResult);
|
||||||
return true;
|
return true;
|
||||||
@ -161,13 +168,17 @@ public class NetworkManager extends CordovaPlugin {
|
|||||||
private void updateConnectionInfo(NetworkInfo info) {
|
private void updateConnectionInfo(NetworkInfo info) {
|
||||||
// send update to javascript "navigator.network.connection"
|
// send update to javascript "navigator.network.connection"
|
||||||
// Jellybean sends its own info
|
// Jellybean sends its own info
|
||||||
String thisStatus = this.getConnectionInfo(info);
|
JSONObject thisInfo = this.getConnectionInfo(info);
|
||||||
if(!thisStatus.equals(lastStatus))
|
if(!thisInfo.equals(lastInfo))
|
||||||
{
|
{
|
||||||
sendUpdate(thisStatus);
|
String connectionType = "";
|
||||||
lastStatus = thisStatus;
|
try {
|
||||||
}
|
connectionType = thisInfo.get("type").toString();
|
||||||
|
} catch (JSONException e) { }
|
||||||
|
|
||||||
|
sendUpdate(connectionType);
|
||||||
|
lastInfo = thisInfo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -176,8 +187,9 @@ public class NetworkManager extends CordovaPlugin {
|
|||||||
* @param info the current active network info
|
* @param info the current active network info
|
||||||
* @return a JSONObject that represents the network info
|
* @return a JSONObject that represents the network info
|
||||||
*/
|
*/
|
||||||
private String getConnectionInfo(NetworkInfo info) {
|
private JSONObject getConnectionInfo(NetworkInfo info) {
|
||||||
String type = TYPE_NONE;
|
String type = TYPE_NONE;
|
||||||
|
String extraInfo = "";
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
// If we are not connected to any network set type to none
|
// If we are not connected to any network set type to none
|
||||||
if (!info.isConnected()) {
|
if (!info.isConnected()) {
|
||||||
@ -186,9 +198,20 @@ public class NetworkManager extends CordovaPlugin {
|
|||||||
else {
|
else {
|
||||||
type = getType(info);
|
type = getType(info);
|
||||||
}
|
}
|
||||||
|
extraInfo = info.getExtraInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d("CordovaNetworkManager", "Connection Type: " + type);
|
Log.d("CordovaNetworkManager", "Connection Type: " + type);
|
||||||
return type;
|
Log.d("CordovaNetworkManager", "Connection Extra Info: " + extraInfo);
|
||||||
|
|
||||||
|
JSONObject connectionInfo = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
connectionInfo.put("type", type);
|
||||||
|
connectionInfo.put("extraInfo", extraInfo);
|
||||||
|
} catch (JSONException e) { }
|
||||||
|
|
||||||
|
return connectionInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -247,3 +270,4 @@ public class NetworkManager extends CordovaPlugin {
|
|||||||
return TYPE_UNKNOWN;
|
return TYPE_UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user