File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
src/src/org/renpy/android Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1616import android .content .BroadcastReceiver ;
1717import android .content .Intent ;
1818import android .content .IntentFilter ;
19+ import android .net .ConnectivityManager ;
20+ import android .net .NetworkInfo ;
1921
2022/**
2123 * Methods that are expected to be called via JNI, to access the
@@ -232,4 +234,48 @@ public static String scanWifi() {
232234 return "" ;
233235 }
234236
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+
235281}
You can’t perform that action at this time.
0 commit comments