File tree 1 file changed +50
-0
lines changed
src/src/org/renpy/android 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 16
16
import android .content .BroadcastReceiver ;
17
17
import android .content .Intent ;
18
18
import android .content .IntentFilter ;
19
+ import android .net .ConnectivityManager ;
20
+ import android .net .NetworkInfo ;
19
21
20
22
/**
21
23
* Methods that are expected to be called via JNI, to access the
@@ -232,4 +234,52 @@ public static String scanWifi() {
232
234
return "" ;
233
235
}
234
236
237
+ /**
238
+ * network state, coarse
239
+ */
240
+
241
+ public static boolean network_state = false ;
242
+
243
+ /**
244
+ * To recieve network state changes
245
+ */
246
+ public static void registerNetworkCheck ()
247
+ {
248
+ IntentFilter i = new IntentFilter ();
249
+ i .addAction (ConnectivityManager .CONNECTIVITY_ACTION );
250
+ context .registerReceiver (new BroadcastReceiver () {
251
+
252
+ @ Override
253
+ public void onReceive (Context c , Intent i ) {
254
+ checkNetwork ();
255
+ }
256
+
257
+ }, i );
258
+ }
259
+
260
+
261
+ /**
262
+ * Check network state directly
263
+ *
264
+ * (only one connection can be active at a given moment, detects al type of networks)
265
+ *
266
+ */
267
+ public static boolean checkNetwork ()
268
+ {
269
+ boolean state = false ;
270
+ final ConnectivityManager conMgr = (ConnectivityManager ) context .getSystemService (Context .CONNECTIVITY_SERVICE );
271
+
272
+ final NetworkInfo activeNetwork = conMgr .getActiveNetworkInfo ();
273
+ if (activeNetwork != null && activeNetwork .isConnected ()) {
274
+ network_state = true ;
275
+ } else {
276
+ network_state = false ;
277
+ }
278
+
279
+ return state ;
280
+ }
281
+
282
+
283
+
284
+
235
285
}
You can’t perform that action at this time.
0 commit comments