Aqui la solucion
Dentro de mi clase que hace la consulta a sqlite
Código Java:
Ver originalpublic JSONObject getJSONfromSQLite(){
JSONObject json_row = new JSONObject();
SQLiteDatabase database = this.getWritableDatabase();
int cont=0;
String selectQuery
= "SELECT id_sqlite, user, company, form, checkBox, date FROM chequeo where status = '2' ";
Cursor cursor
= database.
rawQuery(selectQuery,
null);
if (cursor.moveToFirst()) {
do {
JSONObject json_val = new JSONObject();
try{
cont++;
json_val.put("id_sqlite", cursor.getString(0));
json_val.put("user", cursor.getString(1));
json_val.put("company", cursor.getString(2));
json_val.put("form", cursor.getString(3));
json_val.put("checkBox", cursor.getString(4));
json_val.put("date", cursor.getString(5));
json_row.put("cont"+cont,json_val);
}
{
Log.e("getJSONfromSQLite catch", e.getMessage());
}
} while (cursor.moveToNext());
}
database.close();
JSONObject json = new JSONObject();
try{
json.put("json",json_row);
json.put("cont",cont);
}
Log.e("json catch", e.getMessage());
}
return json;
}
Dentro de la clase que manda los datos al servidor
Código Java:
Ver originalpublic void sync
(View v
) { // Tag used to cancel the request
String tag_string_req
= "req_login";
pDialog.setMessage("Logging in...");
pDialog.show();
StringRequest strReq
= new StringRequest
(Method.
POST,
AppConfig.URL_SYNC, new Response.Listener<String>() {
public void onResponse
(String response
) {
try {
Log.d("Login Response",
"Login Response: " + response.toString());
pDialog.cancel();
String user
= config.
getUser();
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
// Check for error node in json
if (!error) {
// user successfully logged in
// Create login session
int contLogin = objSqlt.getUser(user);
if (contLogin == 0) {
JSONObject obj = jObj.getJSONObject("user");
Integer id_mysql
= obj.
getInt("id_mysql"); String user1
= obj.
getString("user"); String pass_encrypted
= obj.
getString("pass_encrypted"); String pass1
= obj.
getString("pass");
// Inserting row in users table
objSqlt.addUser(id_mysql, user1, pass_encrypted, pass1);
}
} else {
session.setControl_login(false);
String errorMsg
= jObj.
getString("error_msg"); Toast.makeText(getApplicationContext(),
errorMsg, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
public void onErrorResponse(VolleyError error) {
Log.e("Sysn Error: ", "Error en la conexion");
Toast.makeText(getApplicationContext(),
"Error en la conexion", Toast.LENGTH_LONG).show();
pDialog.cancel();
}
}) {
@Override
protected Map
<String, String
> getParams
() { JSONObject json = objSqlt.getJSONfromSQLite();
try{
params.put("json", json.getString("json"));
params.put("cont", json.getString("cont"));
Log.e("getParams", e.getMessage());
}
return params;
}
};
// Adding request to request queue
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}