community-cordova-plugin-wifi 1.0.2 → 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.
- package/.idea/workspace.xml +20 -4
- package/package.json +1 -1
- package/plugin.xml +1 -1
- package/src/android/PingTask.java +1 -1
- package/src/android/WifiPlugin.java +56 -8
package/.idea/workspace.xml
CHANGED
|
@@ -4,10 +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="
|
|
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/WifiPlugin.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/android/WifiPlugin.java" afterDir="false" />
|
|
11
12
|
</list>
|
|
12
13
|
<option name="SHOW_DIALOG" value="false" />
|
|
13
14
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
@@ -91,7 +92,13 @@
|
|
|
91
92
|
<workItem from="1709102390279" duration="5116000" />
|
|
92
93
|
<workItem from="1709959064513" duration="9732000" />
|
|
93
94
|
<workItem from="1710582743464" duration="1835000" />
|
|
94
|
-
<workItem from="1710593259268" duration="
|
|
95
|
+
<workItem from="1710593259268" duration="1509000" />
|
|
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" />
|
|
95
102
|
</task>
|
|
96
103
|
<task id="LOCAL-00001" summary="update plugin">
|
|
97
104
|
<option name="closed" value="true" />
|
|
@@ -157,7 +164,15 @@
|
|
|
157
164
|
<option name="project" value="LOCAL" />
|
|
158
165
|
<updated>1710593285324</updated>
|
|
159
166
|
</task>
|
|
160
|
-
<
|
|
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" />
|
|
161
176
|
<servers />
|
|
162
177
|
</component>
|
|
163
178
|
<component name="TypeScriptGeneratedFilesManager">
|
|
@@ -176,6 +191,7 @@
|
|
|
176
191
|
</component>
|
|
177
192
|
<component name="VcsManagerConfiguration">
|
|
178
193
|
<MESSAGE value="update plugin" />
|
|
179
|
-
<
|
|
194
|
+
<MESSAGE value="fixed progress bar in Ping" />
|
|
195
|
+
<option name="LAST_COMMIT_MESSAGE" value="fixed progress bar in Ping" />
|
|
180
196
|
</component>
|
|
181
197
|
</project>
|
package/package.json
CHANGED
package/plugin.xml
CHANGED
|
@@ -20,10 +20,10 @@ public class PingTask {
|
|
|
20
20
|
String line;
|
|
21
21
|
String fullResponse = "";
|
|
22
22
|
while ((line = reader.readLine()) != null) {
|
|
23
|
+
int progress = (int) (((double) linesRead / count) * 100);
|
|
23
24
|
linesRead++;
|
|
24
25
|
JSONObject progressUpdate = new JSONObject();
|
|
25
26
|
// Ensure progress does not exceed 100
|
|
26
|
-
int progress = (int) (((double) linesRead / count) * 100);
|
|
27
27
|
progress = Math.min(progress, 100); // Cap progress at 100
|
|
28
28
|
progressUpdate.put("line", line);
|
|
29
29
|
if (fullResponse != null && !fullResponse.isEmpty()) {
|
|
@@ -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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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) {
|