Wifi available test ?
Monkey Targets Forums/Android/Wifi available test ?
| ||
Hi, In my project i need to update a file with my server. I use httpget with MNET module. When i have a wifi connexion it works fine. But i tryed it without Wifi it crash at the end. (file is updated but it crash at the end). And the crash is so big i must shutdown and restart my smartphone. So, is there a way (probably with a java extension) to detect if there is a wifi connexion available (i mean with password available)? like this i could autorize or forbid connexion ? Thanks for your ideas. (if you know an other way to make ftp or tcp/udp transfer i am interested to) Best regards Golomp |
| ||
first google hit^^private static boolean isConnected(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = null; if (connectivityManager != null) { networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); } return networkInfo == null ? false : networkInfo.isConnected(); } |
| ||
Wow, lucky ! I search by my side but i only found source code to list all wifi connexion visible around. I am going to try your solution, thank you Rone. Concerning Context parameter, i dont know what to put... I am going to try without parameters... |
| ||
Does somebody have an example of usage ? I try a lot of things but i fail each time. |
| ||
double |
| ||
triple (sorry, dont know how to delete) |
| ||
i have no android sdk installed...but tryBBAndroidGame.AndroidGame().GetGameView().getApplicationContext() or BBAndroidGame.AndroidGame().getApplicationContext() |
| ||
BBAndroidGame is not recognised as an known identifier. Have you a sample ? i could better understand and adapt it to my project. a little thing like : If isConnected(..........) DrawText "Wifi connexion available",30,370 Else DrawText "Wifi connexion not available.",30,370 Endif |
| ||
BBAndroidGame is external(targets/android/modules/native). just like IsConnected ... pseudo code: Import "native/your_network_util.java" extern Function IsConnected?() public If IsConnected DrawText "Wifi connexion available",30,370 Else DrawText "Wifi connexion not available.",30,370 End native/your_network_util.java: private static boolean isConnected() { Context context = BBAndroidGame.AndroidGame().getApplicationContext(); ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = null; if (connectivityManager != null) { networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); } return networkInfo == null ? false : networkInfo.isConnected(); } |
| ||
Thank again for your help Rone. Does this example run on your system ? I use Monkey V0.66 and i cant compile it. Even when i complete with a class and oncreate method. I see what you mean in your java source but i meet a difficulty to obtain appropriate context. I think BBAndroidGame is an identifier belonging to Diddy. I tried to modify line Context context = BBAndroidGame.AndroidGame().getApplicationContext(); but all my tries are actually without success. |
| ||
I have no android sdk installed... it's v69...BBAndroidGame is in targets/android/modules/native. search the native project in order to find Context in v66 |
| ||
No problem Rone, i will wait. There are no urgence. I updated my version to V69 and i found BBAndroidGame in targets/android/modules/native. Thanks. But i still cant compile nor generate an apk. If i was a little bit initiate in java i could probably solve my situation with the elements you give me. But i am not... |