Securely send data from Sqlite to Mysql

0

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!

    
asked by DoubleM 30.03.2017 в 19:41
source

1 answer

0

A query refers to the sending of data, if and only if the network conditions are suitable for data transmission?

  • A serious solution is to send a checksum or verification sum, that is to say that when transmitting the data to your web service it will return a status code indicating if all the data was received and if you can insert everything in your base of data.

  • Or you can obtain the signal strength of your mobile data and depending on whether it is appropriate to send data or not:

TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE); CellInfoGsm cellinfogsm = (CellInfoGsm)telephonyManager.getAllCellInfo().get(0); CellSignalStrengthGsm cellSignalStrengthGsm = cellinfogsm.getCellSignalStrength(); cellSignalStrengthGsm.getDbm();

    
answered by 31.03.2017 в 03:14