List of usage examples for android.content SyncResult hasHardError
public boolean hasHardError()
From source file:com.snu.msl.sensys.SyncAdapter.SyncAdapter.java
@Override public void onPerformSync(Account account, Bundle bundle, String s, ContentProviderClient contentProviderClient, SyncResult syncResult) { Log.d("UPUP", "Reached here"); try {//from w w w. ja va2 s.c om Cursor cursor = contentProviderClient.query( Uri.parse("content://com.snu.msl.sensys.provider/datacollected"), null, null, null, null); cursor.moveToFirst(); StringBuilder res = new StringBuilder(); while (!cursor.isAfterLast()) { String timestamp = cursor.getString(cursor.getColumnIndex("timestamp")); String firstTime = cursor.getString(cursor.getColumnIndex("firsttime")); String gpsLatitude = cursor.getString(cursor.getColumnIndex("gpslatitude")); String gpsLongitude = cursor.getString(cursor.getColumnIndex("gpslongitude")); String sensordroneMAC = cursor.getString(cursor.getColumnIndex("sensordronemac")); String sensordroneTemperature = cursor.getString(cursor.getColumnIndex("sensordronetemperature")); String sensordroneHumidity = cursor.getString(cursor.getColumnIndex("sensordronehumidity")); String sensordronePressure = cursor.getString(cursor.getColumnIndex("sensordronepressure")); String sensordroneIRTemperature = cursor .getString(cursor.getColumnIndex("sensordroneirtemperature")); String sensordroneIlluminance = cursor.getString(cursor.getColumnIndex("sensordroneilluminance")); String sensordronePrecisionGas = cursor.getString(cursor.getColumnIndex("sensordroneprecisiongas")); String sensordroneCapacitance = cursor.getString(cursor.getColumnIndex("sensordronecapacitance")); String sensordroneExternalVoltage = cursor .getString(cursor.getColumnIndex("sensordroneexternalvoltage")); String sensordroneBatteryVoltage = cursor .getString(cursor.getColumnIndex("sensordronebatteryvoltage")); String sensordroneOxidizingGas = cursor.getString(cursor.getColumnIndex("sensordroneoxidizinggas")); String sensordroneReducingGas = cursor.getString(cursor.getColumnIndex("sensordronereducinggas")); String gpsAltitude = cursor.getString(cursor.getColumnIndex("gpsaltitude")); String sensordroneCO2 = cursor.getString(cursor.getColumnIndex("sensordroneco2")); String responseString = ""; HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost( "http://mobisense.webapps.snu.edu.in/ITRAWebsite/upload/sensordroneupload.php"); try { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("user", account.name)); nameValuePairs.add(new BasicNameValuePair("timestamp", timestamp)); nameValuePairs.add(new BasicNameValuePair("firsttime", firstTime)); nameValuePairs.add(new BasicNameValuePair("gpslatitude", gpsLatitude)); nameValuePairs.add(new BasicNameValuePair("gpslongitude", gpsLongitude)); nameValuePairs.add(new BasicNameValuePair("sensordronemac", sensordroneMAC)); nameValuePairs.add(new BasicNameValuePair("sensordronetemperature", sensordroneTemperature)); nameValuePairs.add(new BasicNameValuePair("sensordronehumidity", sensordroneHumidity)); nameValuePairs.add(new BasicNameValuePair("sensordronepressure", sensordronePressure)); nameValuePairs .add(new BasicNameValuePair("sensordroneirtemperature", sensordroneIRTemperature)); nameValuePairs.add(new BasicNameValuePair("sensordroneilluminance", sensordroneIlluminance)); nameValuePairs.add(new BasicNameValuePair("sensordroneprecisiongas", sensordronePrecisionGas)); nameValuePairs.add(new BasicNameValuePair("sensordronecapacitance", sensordroneCapacitance)); nameValuePairs .add(new BasicNameValuePair("sensordroneexternalvoltage", sensordroneExternalVoltage)); nameValuePairs .add(new BasicNameValuePair("sensordronebatteryvoltage", sensordroneBatteryVoltage)); nameValuePairs.add(new BasicNameValuePair("sensordroneoxidizinggas", sensordroneOxidizingGas)); nameValuePairs.add(new BasicNameValuePair("sensordronereducinggas", sensordroneReducingGas)); nameValuePairs.add(new BasicNameValuePair("sensordroneco2", sensordroneCO2)); nameValuePairs.add(new BasicNameValuePair("gpsaltitude", gpsAltitude)); Log.d("TAG", sensordroneOxidizingGas + ", " + sensordroneReducingGas + ", " + sensordroneTemperature); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); responseString = EntityUtils.toString(entity, "UTF-8"); Log.d("TAGFFFF", responseString); } catch (ClientProtocolException e) { // TODO Auto-generated catch block } catch (IOException e) { // TODO Auto-generated catch block } if (responseString.equalsIgnoreCase("Success")) contentProviderClient.delete(Uri.parse("content://com.snu.msl.sensys.provider/datacollected"), "timestamp=?", new String[] { timestamp }); cursor = contentProviderClient.query( Uri.parse("content://com.snu.msl.sensys.provider/datacollected"), null, null, null, null); cursor.moveToFirst(); } } catch (RemoteException e) { syncResult.hasHardError(); e.printStackTrace(); } }