File tree Expand file tree Collapse file tree
src/src/org/renpy/android Expand file tree Collapse file tree 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,52 @@ public static String scanWifi() {
232234 return "" ;
233235 }
234236
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+
235285}
You can’t perform that action at this time.
0 commit comments