File tree 1 file changed +46
-0
lines changed
src/src/org/renpy/android
1 file changed +46
-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,48 @@ public static String scanWifi() {
232
234
return "" ;
233
235
}
234
236
237
+ /**
238
+ * network state
239
+ */
240
+
241
+ public static boolean network_state = false ;
242
+
243
+ /**
244
+ * Check network state directly
245
+ *
246
+ * (only one connection can be active at a given moment, detects all network type)
247
+ *
248
+ */
249
+ public static boolean checkNetwork ()
250
+ {
251
+ boolean state = false ;
252
+ final ConnectivityManager conMgr = (ConnectivityManager ) context .getSystemService (Context .CONNECTIVITY_SERVICE );
253
+
254
+ final NetworkInfo activeNetwork = conMgr .getActiveNetworkInfo ();
255
+ if (activeNetwork != null && activeNetwork .isConnected ()) {
256
+ state = true ;
257
+ } else {
258
+ state = false ;
259
+ }
260
+
261
+ return state ;
262
+ }
263
+
264
+ /**
265
+ * To recieve network state changes
266
+ */
267
+ public static void registerNetworkCheck ()
268
+ {
269
+ IntentFilter i = new IntentFilter ();
270
+ i .addAction (ConnectivityManager .CONNECTIVITY_ACTION );
271
+ context .registerReceiver (new BroadcastReceiver () {
272
+
273
+ @ Override
274
+ public void onReceive (Context c , Intent i ) {
275
+ network_state = checkNetwork ();
276
+ }
277
+
278
+ }, i );
279
+ }
280
+
235
281
}
You can’t perform that action at this time.
0 commit comments