mirror of
https://gitee.com/shuto/cordova-plugin-network-information.git
synced 2025-01-31 10:35:43 +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
|
||||
|
||||
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
|
||||
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-6465: Add license headers to Tizen code
|
||||
* 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"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
id="org.apache.cordova.network-information"
|
||||
version="0.2.9-dev">
|
||||
version="0.2.10-dev">
|
||||
|
||||
<name>Network Information</name>
|
||||
<description>Cordova Network Information Plugin</description>
|
||||
|
@ -24,6 +24,8 @@ import org.apache.cordova.CordovaPlugin;
|
||||
import org.apache.cordova.PluginResult;
|
||||
import org.apache.cordova.CordovaWebView;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
@ -75,7 +77,7 @@ public class NetworkManager extends CordovaPlugin {
|
||||
|
||||
ConnectivityManager sockMan;
|
||||
BroadcastReceiver receiver;
|
||||
private String lastStatus = "";
|
||||
private JSONObject lastInfo = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -104,7 +106,7 @@ public class NetworkManager extends CordovaPlugin {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
// (The null check is for the ARM Emulator, please use Intel Emulator for better results)
|
||||
if(NetworkManager.this.webView != null)
|
||||
if(NetworkManager.this.webView != null)
|
||||
updateConnectionInfo(sockMan.getActiveNetworkInfo());
|
||||
}
|
||||
};
|
||||
@ -126,7 +128,12 @@ public class NetworkManager extends CordovaPlugin {
|
||||
if (action.equals("getConnectionInfo")) {
|
||||
this.connectionCallbackContext = callbackContext;
|
||||
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);
|
||||
callbackContext.sendPluginResult(pluginResult);
|
||||
return true;
|
||||
@ -161,13 +168,17 @@ public class NetworkManager extends CordovaPlugin {
|
||||
private void updateConnectionInfo(NetworkInfo info) {
|
||||
// send update to javascript "navigator.network.connection"
|
||||
// Jellybean sends its own info
|
||||
String thisStatus = this.getConnectionInfo(info);
|
||||
if(!thisStatus.equals(lastStatus))
|
||||
JSONObject thisInfo = this.getConnectionInfo(info);
|
||||
if(!thisInfo.equals(lastInfo))
|
||||
{
|
||||
sendUpdate(thisStatus);
|
||||
lastStatus = thisStatus;
|
||||
String connectionType = "";
|
||||
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
|
||||
* @return a JSONObject that represents the network info
|
||||
*/
|
||||
private String getConnectionInfo(NetworkInfo info) {
|
||||
private JSONObject getConnectionInfo(NetworkInfo info) {
|
||||
String type = TYPE_NONE;
|
||||
String extraInfo = "";
|
||||
if (info != null) {
|
||||
// If we are not connected to any network set type to none
|
||||
if (!info.isConnected()) {
|
||||
@ -186,9 +198,20 @@ public class NetworkManager extends CordovaPlugin {
|
||||
else {
|
||||
type = getType(info);
|
||||
}
|
||||
extraInfo = info.getExtraInfo();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user