community-cordova-plugin-wifi 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,11 +4,11 @@
4
4
  <option name="autoReloadType" value="SELECTIVE" />
5
5
  </component>
6
6
  <component name="ChangeListManager">
7
- <list default="true" id="5a269414-5baa-4c38-b2f3-50c21d305b88" name="Changes" comment="update plugin">
7
+ <list default="true" id="5a269414-5baa-4c38-b2f3-50c21d305b88" name="Changes" comment="fixed progress bar in Ping">
8
8
  <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
9
9
  <change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
10
10
  <change beforePath="$PROJECT_DIR$/plugin.xml" beforeDir="false" afterPath="$PROJECT_DIR$/plugin.xml" afterDir="false" />
11
- <change beforePath="$PROJECT_DIR$/src/android/PingTask.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/android/PingTask.java" afterDir="false" />
11
+ <change beforePath="$PROJECT_DIR$/src/android/WifiPlugin.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/android/WifiPlugin.java" afterDir="false" />
12
12
  </list>
13
13
  <option name="SHOW_DIALOG" value="false" />
14
14
  <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -93,7 +93,12 @@
93
93
  <workItem from="1709959064513" duration="9732000" />
94
94
  <workItem from="1710582743464" duration="1835000" />
95
95
  <workItem from="1710593259268" duration="1509000" />
96
- <workItem from="1711186960914" duration="29000" />
96
+ <workItem from="1711186960914" duration="287000" />
97
+ <workItem from="1720760722451" duration="1035000" />
98
+ <workItem from="1722058180072" duration="23000" />
99
+ <workItem from="1722059814051" duration="697000" />
100
+ <workItem from="1722061550247" duration="21000" />
101
+ <workItem from="1723267322946" duration="2826000" />
97
102
  </task>
98
103
  <task id="LOCAL-00001" summary="update plugin">
99
104
  <option name="closed" value="true" />
@@ -159,7 +164,15 @@
159
164
  <option name="project" value="LOCAL" />
160
165
  <updated>1710593285324</updated>
161
166
  </task>
162
- <option name="localTasksCounter" value="9" />
167
+ <task id="LOCAL-00009" summary="fixed progress bar in Ping">
168
+ <option name="closed" value="true" />
169
+ <created>1711187013726</created>
170
+ <option name="number" value="00009" />
171
+ <option name="presentableId" value="LOCAL-00009" />
172
+ <option name="project" value="LOCAL" />
173
+ <updated>1711187013726</updated>
174
+ </task>
175
+ <option name="localTasksCounter" value="10" />
163
176
  <servers />
164
177
  </component>
165
178
  <component name="TypeScriptGeneratedFilesManager">
@@ -178,6 +191,7 @@
178
191
  </component>
179
192
  <component name="VcsManagerConfiguration">
180
193
  <MESSAGE value="update plugin" />
181
- <option name="LAST_COMMIT_MESSAGE" value="update plugin" />
194
+ <MESSAGE value="fixed progress bar in Ping" />
195
+ <option name="LAST_COMMIT_MESSAGE" value="fixed progress bar in Ping" />
182
196
  </component>
183
197
  </project>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "community-cordova-plugin-wifi",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "types": "./types/index.d.ts",
5
5
  "readme": "README.md",
6
6
  "repository": "EYALIN/community-cordova-plugin-wifi/tree/master",
package/plugin.xml CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
4
4
  id="community-cordova-plugin-wifi"
5
- version="1.0.3">
5
+ version="1.0.4">
6
6
  <name>Cordova Plugin Wifi</name>
7
7
  <description></description>
8
8
  <license>MIT</license>
@@ -22,6 +22,8 @@ import org.json.JSONArray;
22
22
  import org.json.JSONException;
23
23
  import org.json.JSONObject;
24
24
 
25
+ import android.util.Log;
26
+
25
27
  import java.util.List;
26
28
 
27
29
  public class WifiPlugin extends CordovaPlugin {
@@ -116,14 +118,60 @@ public class WifiPlugin extends CordovaPlugin {
116
118
  }
117
119
 
118
120
  private void isConnectedToInternet(CallbackContext callbackContext) {
119
- ConnectivityManager connectivityManager = (ConnectivityManager) cordova.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
120
- if (connectivityManager != null) {
121
- NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
122
- boolean isConnected = activeNetworkInfo != null && activeNetworkInfo.isConnected();
123
- callbackContext.success(isConnected ? 1 : 0);
124
- } else {
125
- callbackContext.error("ConnectivityManager is null");
126
- }
121
+ ConnectivityManager connectivityManager = (ConnectivityManager) cordova.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
122
+ if (connectivityManager != null) {
123
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
124
+ Network network = connectivityManager.getActiveNetwork();
125
+ if (network != null) {
126
+ NetworkCapabilities networkCapabilities = connectivityManager.getNetworkCapabilities(network);
127
+ if (networkCapabilities != null) {
128
+ boolean isConnected = networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) &&
129
+ networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED) &&
130
+ networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED) &&
131
+ networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_SUSPENDED);
132
+
133
+ if (isConnected) {
134
+ boolean isWiFi = networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI);
135
+ boolean isCellular = networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR);
136
+ boolean isVPN = networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN);
137
+
138
+ // You can now use these flags to determine the type of connection
139
+ if (isWiFi) {
140
+ // Connected via WiFi
141
+ Log.d(TAG, "Connected via WiFi");
142
+ callbackContext.success(1); // or handle accordingly
143
+ } else if (isCellular) {
144
+ // Connected via Cellular
145
+ Log.d(TAG, "Connected via Cellular");
146
+ callbackContext.success(1); // or handle accordingly
147
+ } else if (isVPN) {
148
+ // Connected via VPN
149
+ Log.d(TAG, "Connected via VPN");
150
+ callbackContext.success(1); // or handle accordingly
151
+ } else {
152
+ // Unknown or unsupported transport
153
+ Log.d(TAG, "Connected via Unknown or unsupported transport");
154
+ callbackContext.success(1); // or handle accordingly
155
+ }
156
+ } else {
157
+ callbackContext.success(0); // No internet connection
158
+ }
159
+ } else {
160
+ callbackContext.success(0); // No internet connection
161
+ }
162
+ } else {
163
+ callbackContext.success(0); // No network connection
164
+ }
165
+ } else {
166
+ // For devices with SDK < 23, you can still use the deprecated method
167
+ NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
168
+ boolean isConnected = activeNetworkInfo != null && activeNetworkInfo.isConnected();
169
+ callbackContext.success(isConnected ? 1 : 0);
170
+ }
171
+ } else {
172
+ Log.e(TAG, "ConnectivityManager is null");
173
+ callbackContext.success(0);
174
+ }
127
175
  }
128
176
 
129
177
  private void canConnectToInternet(CallbackContext callbackContext) {