1. Are you ready for the Galaxy S20? Here is everything we know so far!

Send data only when connected to WiFi?

Discussion in 'Android Development' started by Longshorts, Apr 26, 2012.

  1. Longshorts

    Longshorts Lurker
    Thread Starter

    I am trying to conduct a bit of research before starting to develop an android application I am planning. I want the application to exhibit the following behavior:

    1. If connected to WiFi, send and receive messages to remote server
    2. Else If not connected to WiFi, do not send any messages. Display error message.

    I am trying to create an ethical application so users will not be charged when they become disconnected from WiFi without them noticing. If you could please point me towards any existing source/documentation on how to do this I would be grateful.

    1. Download the Forums for Android™ app!


  2. krishnan

    krishnan Newbie

    Here is the codelet which you could use to check is your device connected to any Wifi.

    Code (Text):
    1.         ConnectivityManager conMgr = (ConnectivityManager) getApplicationContext()
    2.                 .getSystemService(Context.CONNECTIVITY_SERVICE);
    3.         NetworkInfo netInfo = conMgr
    4.                 .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    6.         boolean isConnected = netInfo.isConnected();

    Longshorts likes this.

Share This Page