1. Download our Official Android App: Forums for Android!

Apps Send data only when connected to WiFi?

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

  1. Longshorts

    Longshorts Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Jan 3, 2012

    Jan 3, 2012
    2
    0
    5
    Customer Consultant, Carphone Warehouse
    St. Andrews, Fife, Scotland
    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.
     

    Advertisement

  2. krishnan

    krishnan Newbie
    Rank:
    None
    Points:
    16
    Posts:
    10
    Joined:
    Jun 10, 2010

    Jun 10, 2010
    10
    1
    16
    Hi
    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);
    5.  
    6.         boolean isConnected = netInfo.isConnected();

    -
     
    Longshorts likes this.

Share This Page

Loading...