community-cordova-plugin-wifi 1.0.3 → 1.0.5

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,12 @@
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="isConnectedToTheInternet - Support SDK&gt;29">
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/IpInfoUtils.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/android/IpInfoUtils.java" afterDir="false" />
12
+ <change beforePath="$PROJECT_DIR$/src/android/WifiPlugin.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/android/WifiPlugin.java" afterDir="false" />
12
13
  </list>
13
14
  <option name="SHOW_DIALOG" value="false" />
14
15
  <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -93,7 +94,12 @@
93
94
  <workItem from="1709959064513" duration="9732000" />
94
95
  <workItem from="1710582743464" duration="1835000" />
95
96
  <workItem from="1710593259268" duration="1509000" />
96
- <workItem from="1711186960914" duration="29000" />
97
+ <workItem from="1711186960914" duration="287000" />
98
+ <workItem from="1720760722451" duration="1035000" />
99
+ <workItem from="1722058180072" duration="23000" />
100
+ <workItem from="1722059814051" duration="697000" />
101
+ <workItem from="1722061550247" duration="21000" />
102
+ <workItem from="1723267322946" duration="4719000" />
97
103
  </task>
98
104
  <task id="LOCAL-00001" summary="update plugin">
99
105
  <option name="closed" value="true" />
@@ -159,7 +165,15 @@
159
165
  <option name="project" value="LOCAL" />
160
166
  <updated>1710593285324</updated>
161
167
  </task>
162
- <option name="localTasksCounter" value="9" />
168
+ <task id="LOCAL-00009" summary="fixed progress bar in Ping">
169
+ <option name="closed" value="true" />
170
+ <created>1711187013726</created>
171
+ <option name="number" value="00009" />
172
+ <option name="presentableId" value="LOCAL-00009" />
173
+ <option name="project" value="LOCAL" />
174
+ <updated>1711187013726</updated>
175
+ </task>
176
+ <option name="localTasksCounter" value="10" />
163
177
  <servers />
164
178
  </component>
165
179
  <component name="TypeScriptGeneratedFilesManager">
@@ -178,6 +192,7 @@
178
192
  </component>
179
193
  <component name="VcsManagerConfiguration">
180
194
  <MESSAGE value="update plugin" />
181
- <option name="LAST_COMMIT_MESSAGE" value="update plugin" />
195
+ <MESSAGE value="fixed progress bar in Ping" />
196
+ <option name="LAST_COMMIT_MESSAGE" value="fixed progress bar in Ping" />
182
197
  </component>
183
198
  </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.5",
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.5">
6
6
  <name>Cordova Plugin Wifi</name>
7
7
  <description></description>
8
8
  <license>MIT</license>
@@ -18,6 +18,7 @@ import org.apache.cordova.PluginResult;
18
18
  import org.json.JSONArray;
19
19
  import org.json.JSONException;
20
20
  import org.json.JSONObject;
21
+ import android.util.Log;
21
22
 
22
23
  import java.io.IOException;
23
24
  import java.util.ArrayList;
@@ -123,28 +124,44 @@ public class IpInfoUtils {
123
124
  }
124
125
  }
125
126
 
126
- private static void fillLocationInfo(JSONObject ipInfoObject, LocationManager locationManager, CordovaInterface cordova) throws IOException, JSONException {
127
- Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
128
- if (location != null) {
129
- ipInfoObject.put("latitude", location.getLatitude());
130
- ipInfoObject.put("longitude", location.getLongitude());
131
- List<Address> addresses = new ArrayList<>();
132
- if (isNetworkAvailable(cordova.getActivity())) {
133
- Geocoder geocoder = new Geocoder(cordova.getActivity(), Locale.getDefault());
134
- addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
135
- }
127
+ private static void fillLocationInfo(JSONObject ipInfoObject, LocationManager locationManager, CordovaInterface cordova) throws JSONException {
128
+ Log.d(TAG, "fillLocationInfo begin");
129
+ Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
130
+ if (location != null) {
131
+ Log.d(TAG, "fillLocationInfo location is exists");
132
+ ipInfoObject.put("latitude", location.getLatitude());
133
+ ipInfoObject.put("longitude", location.getLongitude());
134
+ Log.d(TAG, "fillLocationInfo finish lat and long");
135
+
136
+ List<Address> addresses = new ArrayList<>();
137
+ if (isNetworkAvailable(cordova.getActivity())) {
138
+ try {
139
+ Log.d(TAG, "Geocoder begin");
140
+ Geocoder geocoder = new Geocoder(cordova.getActivity(), Locale.getDefault());
141
+ Log.d(TAG, "Geocoder success");
142
+ addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
143
+ Log.d(TAG, "addresses success");
144
+ } catch (IOException e) {
145
+ Log.e(TAG, "Geocoder failed due to network or I/O issues", e);
146
+ } catch (IllegalArgumentException e) {
147
+ Log.e(TAG, "Geocoder failed due to illegal arguments", e);
148
+ } catch (Exception e) {
149
+ Log.e(TAG, "Geocoder failed due to an unexpected error", e);
150
+ }
151
+ }
152
+
153
+ if (!addresses.isEmpty()) {
154
+ Address address = addresses.get(0);
155
+ ipInfoObject.put("city", address.getLocality());
156
+ ipInfoObject.put("street", address.getThoroughfare());
157
+ ipInfoObject.put("country", address.getCountryName());
158
+ ipInfoObject.put("region", address.getSubAdminArea());
159
+ ipInfoObject.put("zipcode", address.getPostalCode());
160
+ ipInfoObject.put("state", address.getAdminArea());
161
+ }
162
+ }
163
+ }
136
164
 
137
- if (!addresses.isEmpty()) {
138
- Address address = addresses.get(0);
139
- ipInfoObject.put("city", address.getLocality());
140
- ipInfoObject.put("street", address.getThoroughfare());
141
- ipInfoObject.put("country", address.getCountryName());
142
- ipInfoObject.put("region", address.getSubAdminArea());
143
- ipInfoObject.put("zipcode", address.getPostalCode());
144
- ipInfoObject.put("state", address.getAdminArea());
145
- }
146
- }
147
- }
148
165
 
149
166
  public static boolean isNetworkAvailable(Context context) {
150
167
  ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
@@ -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) {