public
class CheckNetwork extends BroadcastReceiver {
@Override
public
void onReceive(Context context, Intent intent) {
if (checkNetworkConnection(context)){
//Toast.makeText(context,"Start",Toast.LENGTH_LONG).show();
attDBAdapter = new com.example.sg.empattedance.AttDBAdapter(context);
Cursor str=attDBAdapter.getAttandancedata12("X");
Log.d("waliasir", "onCreate: "+str);
if (str!= null) {
str.moveToFirst();
while(!str.isAfterLast()){
//for (int i = 0; i <str.getCount(); i++) {
indate.add(str.getString(str.getColumnIndex("InDate")));
intime.add(str.getString(str.getColumnIndex("InTime")));
outdate.add(str.getString(str.getColumnIndex("OutDate")));
outtime.add(str.getString(str.getColumnIndex("OutTime")));
igeoid.add(str.getString(str.getColumnIndex("IGeoId")));
imei_no.add(str.getString(str.getColumnIndex("Imei_No")));
inlatitude.add(str.getString(str.getColumnIndex("InLatitude")));
inlongitude.add(str.getString(str.getColumnIndex("InLongitude")));
outlatitude.add(str.getString(str.getColumnIndex("OutLatitude")));
outlongitude.add(str.getString(str.getColumnIndex("OutLongitude")));
str.moveToNext();
}
str.close();
}
for(int i=0; i< igeoid.size();i++){
final int finalI1 = i;
StringRequest stringRequest = new StringRequest(Request.Method.POST,URL_NAHAR_PUNCH,
new Response.Listener<String>() {
@Override
public
void onResponse(String response) {
Log.d("Arvind", "onResp"+response);
try {
JSONObject jobjet= new JSONObject(response);
String result=String.valueOf(jobjet.get("error"));
String result1=String.valueOf(jobjet.get("message"));
Log.d("pakkgai", "onResponse: "+result1);
if (result.equals("1"))
{
long id =attDBAdapter.UpdateLocalUserAttendancesync(result1,"Y");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public
void onErrorResponse(VolleyError error) {
Log.d("shubham", "onResponse3: "+error);
}
}){
@Override
protected
Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("Imei_No",imei_no.get(finalI1));
params.put("InDate",indate.get(finalI1));
params.put("InTime",intime.get(finalI1));
params.put("OutDate",outdate.get(finalI1));
params.put("OutTime",outtime.get(finalI1));
params.put("IsSync","Y");
params.put("Inlatitude",inlatitude.get(finalI1));
params.put("Inlongitude",inlongitude.get(finalI1));
params.put("IGeoId",igeoid.get(finalI1));
params.put("outLatitude",outlatitude.get(finalI1));
params.put("outLongitude",outlongitude.get(finalI1));
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(context);
requestQueue.add(stringRequest);
}
/*
String strparts[]=str.split(",");
if (!strparts[0].equals("")){
for(int j=0;j<strparts.length;j++){
if(j == 0){
//server get
String id = strparts[0].toString().trim();
final String indate=strparts[1].toString();
final String imei_no= strparts[2].toString();
final String igeoid=strparts[3].toString();
final String intime= strparts[4].toString();
final String outtime = strparts[5].toString();
final String outdate= strparts[6].toString();
String issync=strparts[7].toString();
Toast.makeText(context,""+indate+""+intime+"",Toast.LENGTH_LONG).show();
StringRequest stringRequest = new StringRequest(Request.Method.POST,URL_NAHAR_PUNCH,
new Response.Listener<String>() {
@Override
public
void onResponse(String response) {
Log.d("Arvind", "onResponse2: "+response);
try {
JSONObject jobjet= new JSONObject(response);
String result=String.valueOf(jobjet.get("error"));
String result1=String.valueOf(jobjet.get("message"));
Log.d("pakkgai", "onResponse: "+result1);
if (result.equals("1"))
{
long id =attDBAdapter.UpdateLocalUserAttendancesync(result1,"Y");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public
void onErrorResponse(VolleyError error) {
Log.d("shubham", "onResponse3: "+error);
}
}){
@Override
protected
Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("Imei_No",imei_no);
params.put("InDate",indate);
params.put("InTime",intime);
params.put("OutDate",outdate);
params.put("OutTime",outtime);
params.put("IsSync","Y");
params.put("IGeoId",igeoid);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(context);
requestQueue.add(stringRequest);
}
}
}
* /
Cursor str1 = attDBAdapter.getloghistory12("X");
Log.d("waliasir", "onCreate: "+str1);
if (str1 != null) {
str1.moveToFirst();
while(!str1.isAfterLast()){
// for (int j = 0; j < str1.getCount(); j++) {
imei_no1.add(str1.getString(str1.getColumnIndex("Imei_No")));
current_lng.add(str1.getString(str1.getColumnIndex("current_longitude")));
current_lat.add(str1.getString(str1.getColumnIndex("current_latitude")));
date.add(str1.getString(str1.getColumnIndex("Date")));
time.add(str1.getString(str1.getColumnIndex("Time")));
isstatus.add(str1.getString(str1.getColumnIndex("Isstatus")));
igeoid1.add(str1.getString(str1.getColumnIndex("IGeoId")));
gpsstatus.add(str1.getString(str1.getColumnIndex("GpsStatus")));
locationalname.add(str1.getString(str1.getColumnIndex("LocationName")));
// Spoofing.add(str1.getString(str1.getColumnIndex("Spoofing")));
str1.moveToNext();
}
str1.close();
}
for (int j = 0; j < igeoid1.size(); j++) {
final int finalJ = j;
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL_NAHAR_PUNCH1,
new Response.Listener<String>() {
@Override
public
void onResponse(String response) {
Log.d("Arvind", "onResponse2: " + response);
try {
JSONObject jobjet = new JSONObject(response);
String result1 = String.valueOf(jobjet.get("error"));
String message = String.valueOf(jobjet.get("message"));
JSONObject jobjet1 = new JSONObject(message);
String date1 = String.valueOf(jobjet1.get("Date"));
String time1 = String.valueOf(jobjet1.get("Time"));
Log.d("Arvind", "onResponse2: " + time1);
if (result1.equals("1")) {
long id = attDBAdapter.UpdateLocaluserHistory(date1, time1, "Y");
} else {
}
} catch (JSONException e) {
Log.d("anilji", "error: " + e);
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public
void onErrorResponse(VolleyError error) {
Log.d("anil", "onResponse3: " + error);
}
}) {
@Override
protected
Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("Imei_No", imei_no1.get(finalJ));
params.put("Date", date.get(finalJ));
// sharedPref.setdate(date.get(finalJ));
// Log.d("anil", "getParams: " +sharedPref.getdate());
params.put("Time", time.get(finalJ));
//sharedPref.setTime(time.get(finalJ));
// Log.d("anil", "getParams: " +sharedPref.gettime());
params.put("Isstatus", isstatus.get(finalJ));
params.put("IGeoId", igeoid1.get(finalJ));
params.put("current_longitude", current_lng.get(finalJ));
params.put("current_latitude", current_lat.get(finalJ));
params.put("Location_Name", locationalname.get(finalJ));
params.put("GpsStatus", gpsstatus.get(finalJ));
// params.put("Spoofing", Spoofing .get(finalJ));
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(context);
requestQueue.add(stringRequest);
}
/* String strparts1[]=str1.split(",");
if (!strparts1[0].equals("")){
for(int j=0;j<strparts1.length;j++){
if(j == 0){
//server get
String id = strparts1[0].toString().trim();
final String imei_no=strparts1[1].toString();
final String current_lat= strparts1[2].toString();
final String current_lng=strparts1[3].toString();
final String Date= strparts1[4].toString();
final String time = strparts1[5].toString();
final String Isstatus= strparts1[6].toString();
final String Igeoid= strparts1[7].toString();
final String Isync= strparts1[8].toString();
StringRequest stringRequest = new StringRequest(Request.Method.POST,URL_NAHAR_PUNCH1,
new Response.Listener<String>() {
@Override
public
void onResponse(String response) {
Log.d("Arvind", "onResponse2: "+response);
try {
JSONObject jobjet = new JSONObject(response);
String result1 = String.valueOf(jobjet.get("error"));
if (result1.equals("1")){
long id =attDBAdapter.UpdateLocaluserHistory(result1,"Y");
}else{
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public
void onErrorResponse(VolleyError error) {
Log.d("shubham", "onResponse3: "+error);
}
}){
@Override
protected
Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("Imei_No",imei_no);
params.put("Date",Date);
params.put("Time",time);
params.put("Isstatus",Isstatus);
params.put("IGeoId",Igeoid);
params.put("current_longitude", current_lng);
params.put("current_latitude",current_lat);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(context);
requestQueue.add(stringRequest);
}
}
}*/
}
}
public boolean checkNetworkConnection(Context context){
ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
return (networkInfo!=null && networkInfo.isConnected());
}
}