I have an app in which data gets stored in local database. All i want is to send this data to server whenever internet is connected and this process should be performed without starting app just like yahoo mail and watsapp. Thnx in advance.
Asked
Active
Viewed 657 times
1
-
duplicate question: http://stackoverflow.com/questions/15698790/broadcast-receiver-for-checking-internet-connection-in-android-app – NaviRamyle Sep 25 '15 at 09:27
3 Answers
0
You can use a BroadcastReceiver
that listens if the internet connection is available or not and if it's available it sends the saved data without starting the app.

SaNtoRiaN
- 2,212
- 2
- 15
- 25
-
-
@IannHarper This is the broadcast link http://viralpatel.net/blogs/android-internet-connection-status-network-change/ but you'll need to write the code that sends the data to the server yourself – SaNtoRiaN Sep 25 '15 at 09:31
0
- You should learn how to user
Service
to send data toServer
without open your app. - You should learn about
BroadcastReceiver
and useConnectivityManager.CONNECTIVITY_ACTION
to check internet connection status.

Kingfisher Phuoc
- 8,052
- 9
- 46
- 86
0
Use
public class Reciever extends BroadcastReceiver {
@Override
public void onReceive(final Context context, final Intent intent) {
if(isNetworkAvailable(context))
{
// Call your asynctask here for sending data to server.
}
}
public static boolean isNetworkAvailable(Context context) {
try{
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnected()) {
return true;
}
}catch(Exception e){
e.printStackTrace();
}
return false;
}
}

KishuDroid
- 5,411
- 4
- 30
- 47