Wifi available test ?

Monkey Targets Forums/Android/Wifi available test ?

golomp(Posted 2013) [#1]
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


Rone(Posted 2013) [#2]
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();
}



golomp(Posted 2013) [#3]
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...


golomp(Posted 2013) [#4]
Does somebody have an example of usage ? I try a lot of things
but i fail each time.


golomp(Posted 2013) [#5]
double


golomp(Posted 2013) [#6]
triple (sorry, dont know how to delete)


Rone(Posted 2013) [#7]
i have no android sdk installed...but try

BBAndroidGame.AndroidGame().GetGameView().getApplicationContext()

or

BBAndroidGame.AndroidGame().getApplicationContext()



golomp(Posted 2013) [#8]
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



Rone(Posted 2013) [#9]
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();
}



golomp(Posted 2013) [#10]
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.


Rone(Posted 2013) [#11]
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


golomp(Posted 2013) [#12]
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...