I am doing a synchronization of information that is stored in the database Sqlite
my problem esque is a field application that is to say it will work with mobile data, but I have problem that the sending of information is not executed correctly miss sqlite information.
Synchronize Data This is the first method I run to check if there is internet and thus run SendData ();
private class SincronizarDatos extends AsyncTask<Void, Void, Void> {
public void onPreExecute() {
precarga.setVisibility(View.VISIBLE);
}
public void onPostExecute(Void unused) {
}
@Override
protected Void doInBackground(Void... params) {
if (isOnline(getApplicationContext())){
//existe conectividad
EnviarDatos();
}else{
//No existe conectividad.
Toast.makeText(getApplicationContext(), "No existe conectividad", Toast.LENGTH_LONG).show();
}
return null;
}
}
Sending of information We go through all the bdd sqlite and we are eliminating as fence by sending
public void EnviarDatos() {
SQLiteDatabase db = basededatos.getReadableDatabase();
Cursor cursor = db.query(basededatos.TABLE_CAJAS, new String[]{"fecha", "rancho", "sector", "trabajador","hora","_id"}, null, null, null, null, null);
if (cursor.moveToFirst()) {
do {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("fecha", cursor.getString(0));
parameters.put("rancho", cursor.getString(1));
parameters.put("sector", cursor.getString(2));
parameters.put("trabajador", cursor.getString(3));
parameters.put("hora", cursor.getString(4));
ProcessRequest(parameters);
//Eliminamos la fila ya enviada.
basededatos.EliminarDatos(cursor.getString(5));
} while (cursor.moveToNext());
}
}
Lastly, we sent information to Mysql
private void ProcessRequest(final Map<String, String> parameters) {
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL_ENVIARDATOS, new Response.Listener<String>() {
@Override
public void onResponse(String s) {
//Log.d("Respuesta del servidor",s.toString());
precarga.setVisibility(View.INVISIBLE);
onPostResume();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
// Toast.makeText(Menu_AgroMovil.this, "Error al enviar datos ...", Toast.LENGTH_SHORT).show();
//Log.d("Respuesta del servidor",volleyError.getMessage());
precarga.setVisibility(View.INVISIBLE);
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
return parameters;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
My question is how can I be verifying the internet or mobile data so that if there is no access or does not have MB to send, do not run the tasks. Greetings!