I'm trying to develop an application that uploads data from sqlitedatabase to mysql database.
When internet connectivity is not available data only saves to sqlitedatabase and when connectivity is available it uploads data in the sqlitedatabase to mysql database.
When i save data on my app,it saves it in sqlitedatabase,i have code to upload the data to mysql but i'm trying to get the upload action performed whenever network connectivity is available...hope my question is clearer now?
you can use a broadcast receiver and wait for the action ConnectivityManager.CONNECTIVITY_ACTION
see this document
and when you receive ConnectivityManager.CONNECTIVITY_ACTION
initiate a webservice call from your application which will send data to your mysql database.
Ex:
broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
ConnectivityManager connectivity = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] info = connectivity.getAllNetworkInfo();
//Play with the info about current network state
}
}
};
intentFilter = new IntentFilter();
intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(broadcastReceiver, intentFilter);