Example usage for android.content ContentProviderClient delete

List of usage examples for android.content ContentProviderClient delete

Introduction

In this page you can find the example usage for android.content ContentProviderClient delete.

Prototype

public int delete(@NonNull Uri url, @Nullable String selection, @Nullable String[] selectionArgs)
        throws RemoteException 

Source Link

Document

See ContentProvider#delete ContentProvider.delete

Usage

From source file:com.rukman.emde.smsgroups.platform.GMSContactOperations.java

public static int removeGroupFromContacts(ContentProviderClient provider, Account account, long rawContactId,
        SyncResult result) throws RemoteException {
    Uri uri = addCallerIsSyncAdapterParameter(ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId),
            true);/*from   ww w  . j av a  2  s . c o m*/
    return provider.delete(uri, null, null);
}

From source file:fr.free.nrw.commons.contributions.ContributionDao.java

public void delete(Contribution contribution) {
    ContentProviderClient db = clientProvider.get();
    try {/* w w  w. ja  va  2s.c om*/
        if (contribution.getContentUri() == null) {
            // noooo
            throw new RuntimeException("tried to delete item with no content URI");
        } else {
            db.delete(contribution.getContentUri(), null, null);
        }
    } catch (RemoteException e) {
        throw new RuntimeException(e);
    } finally {
        db.release();
    }
}

From source file:org.kontalk.sync.Syncer.java

private int deleteAll(Account account, ContentProviderClient provider) throws RemoteException {
    return provider.delete(RawContacts.CONTENT_URI.buildUpon()
            .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true")
            .appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name)
            .appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type).build(), null, null);
}

From source file:org.kontalk.sync.Syncer.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private int deleteProfile(Account account, ContentProviderClient provider) throws RemoteException {
    return provider.delete(ContactsContract.Profile.CONTENT_RAW_CONTACTS_URI.buildUpon()
            .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true")
            .appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name)
            .appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type).build(), null, null);
}

From source file:com.clearcenter.mobile_demo.mdSyncAdapter.java

public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
        SyncResult syncResult) {//from   www . ja  va 2  s .c  o m
    String authtoken = null;
    Log.i(TAG, "Starting sync operation...");

    try {
        mdSSLUtil.DisableSecurity();

        // Use the account manager to request the AuthToken we'll need
        // to talk to our sample server.  If we don't have an AuthToken
        // yet, this could involve a round-trip to the server to request
        // an AuthToken.
        authtoken = account_manager.blockingGetAuthToken(account, mdConstants.AUTHTOKEN_TYPE,
                NOTIFY_AUTH_FAILURE);

        final String hostname = account_manager.getUserData(account, "hostname");

        long _last_sample = -1;
        if (last_sample.containsKey(account.name))
            _last_sample = last_sample.get(account.name);

        // Get sync data from server...
        final String data = mdRest.GetSystemInfo(hostname, authtoken, _last_sample);

        // Something went wrong :^(
        if (TextUtils.isEmpty(data))
            return;

        if (_last_sample < 0) {
            int count = provider.delete(mdDeviceSamples.CONTENT_URI, mdDeviceSamples.NICKNAME + " = ?",
                    new String[] { account.name });

            Log.d(TAG, "Reset database, purged " + count + " samples.");
        }

        try {
            JSONObject json_data = new JSONObject(data);
            if (json_data.has("time"))
                _last_sample = Long.valueOf(json_data.getString("time"));
            Log.d(TAG, account.name + ": last sample time-stamp: " + _last_sample);
        } catch (JSONException e) {
            Log.e(TAG, "JSONException", e);
            return;
        }

        last_sample.put(account.name, _last_sample);

        ContentValues values = new ContentValues();
        values.put(mdDeviceSamples.NICKNAME, account.name);
        values.put(mdDeviceSamples.DATA, data);

        provider.insert(mdDeviceSamples.CONTENT_URI, values);

        String projection[] = new String[] { mdDeviceSamples.SAMPLE_ID };

        Cursor cursor = provider.query(mdDeviceSamples.CONTENT_URI, projection,
                mdDeviceSamples.NICKNAME + " = ?", new String[] { account.name }, mdDeviceSamples.SAMPLE_ID);

        int rows = cursor.getCount();
        Log.d(TAG, "Rows: " + rows);
        if (rows <= mdConstants.MAX_SAMPLES) {
            cursor.close();
            return;
        }

        Log.d(TAG, "Samples to purge: " + (rows - mdConstants.MAX_SAMPLES));
        cursor.move(rows - mdConstants.MAX_SAMPLES);

        int top_id = cursor.getInt(cursor.getColumnIndex(mdDeviceSamples.SAMPLE_ID));
        Log.d(TAG, "Top ID: " + top_id);

        cursor.close();

        int count = provider.delete(mdDeviceSamples.CONTENT_URI,
                mdDeviceSamples.SAMPLE_ID + " <= ? AND " + mdDeviceSamples.NICKNAME + " = ?",
                new String[] { String.valueOf(top_id), account.name });

        Log.d(TAG, "Purged " + count + " samples.");

    } catch (final RemoteException e) {
        Log.e(TAG, "RemoteException", e);
        syncResult.stats.numParseExceptions++;
    } catch (final AuthenticatorException e) {
        Log.e(TAG, "AuthenticatorException", e);
        syncResult.stats.numParseExceptions++;
    } catch (final OperationCanceledException e) {
        Log.e(TAG, "OperationCanceledExcetpion", e);
    } catch (final IOException e) {
        Log.e(TAG, "IOException", e);
        syncResult.stats.numIoExceptions++;
    } catch (final ParseException e) {
        Log.e(TAG, "ParseException", e);
        syncResult.stats.numParseExceptions++;
    } catch (final AuthenticationException e) {
        Log.e(TAG, "AuthenticationException", e);
        syncResult.stats.numAuthExceptions++;
        account_manager.invalidateAuthToken(mdConstants.AUTHTOKEN_TYPE, authtoken);
    } catch (GeneralSecurityException e) {
        Log.e(TAG, "GeneralSecurityException", e);
    } catch (final JSONException e) {
        Log.e(TAG, "JSONException", e);
        syncResult.stats.numParseExceptions++;
    }
}

From source file:com.taxicop.sync.SyncAdapter.java

@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
        SyncResult syncResult) {//from   ww w .j ava 2s.  c o m

    USER = queryUser(provider);
    Log.i(TAG, "onPerformSync: Start");
    NetworkUtilities.reset();
    FROM = queryLastId(provider);
    Log.d(TAG, "data from= " + FROM);
    ArrayList<Complaint> queries = query(provider, FROM);
    NetworkUtilities.add(USER);
    for (Complaint c : queries) {
        NetworkUtilities.add(c.RANKING, c.CAR_PLATE, c.DESCRIPTION, c.USER, c.DATE);
    }
    Log.d(TAG, "from= " + FROM + " size del query= " + queries.size());

    String response = null;
    if (NetworkUtilities.adapter.size() > 0) {
        response = ":" + NetworkUtilities.process_upload();
        Log.i(TAG, "response: " + response);
    } else
        Log.i(TAG, "no data");

    if (USER != null) {
        NetworkUtilities.reset();
        NetworkUtilities.add(USER);
        NetworkUtilities.add(FROM);
        response = null;
        if (NetworkUtilities.adapter.size() > 0) {
            response = NetworkUtilities.process_download();
            Log.d(TAG, "" + response);
        } else
            Log.e(TAG, "no data");
        try {
            if (response != null) {
                final JSONArray cars = new JSONArray(response);
                provider.delete(PlateContentProvider.URI_REPORT, null, null);
                Log.i(TAG, "" + response);
                for (int i = 0; i < cars.length(); i++) {
                    JSONObject COMPLETE = cars.getJSONObject(i);
                    JSONObject e1 = COMPLETE.getJSONObject("fields");
                    float rank = (float) e1.getDouble(Fields.RANKING);
                    String car = e1.getString(Fields.CAR_PLATE);
                    String desc = e1.getString(Fields.DESCRIPTION);
                    String date = e1.getString(Fields.DATE_REPORT);
                    ContentValues in = new ContentValues();
                    in.put(Fields.ID_KEY, i);
                    in.put(Fields.CAR_PLATE, car);
                    in.put(Fields.RANKING, rank);
                    in.put(Fields.DATE_REPORT, date);
                    in.put(Fields.DESCRIPTION, desc);
                    insert.add(in);
                }
                Log.d(TAG, "current ammount to insert= " + insert.size() + ",  FROM=" + FROM);
                ContentValues upd = new ContentValues();
                upd.put(Fields.ITH, insert.size());
                upd.put(Fields.ID_USR, USER);

                provider.update(PlateContentProvider.URI_USERS, upd, "" + Fields.ID_USR + " = '" + USER + "'",
                        null);
                //if(insert.size()>FROM)
                provider.applyBatch(insertData());
                insert.clear();
            } else {
                Log.e(TAG, "null response");
            }

        } catch (Exception e) {
            Log.e(TAG, "inserting .... fucked => message: " + e.getMessage());
        }

    }

}

From source file:com.owncloud.android.datamodel.FileDataStorageManager.java

public void deleteFileInMediaScan(String path) {

    String mimetypeString = FileStorageUtils.getMimeTypeFromName(path);
    ContentResolver contentResolver = getContentResolver();

    if (contentResolver != null) {
        if (mimetypeString.startsWith("image/")) {
            // Images
            contentResolver.delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                    MediaStore.Images.Media.DATA + "=?", new String[] { path });
        } else if (mimetypeString.startsWith("audio/")) {
            // Audio
            contentResolver.delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                    MediaStore.Audio.Media.DATA + "=?", new String[] { path });
        } else if (mimetypeString.startsWith("video/")) {
            // Video
            contentResolver.delete(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
                    MediaStore.Video.Media.DATA + "=?", new String[] { path });
        }/*from  w w  w  . j a  v a  2  s  .com*/
    } else {
        ContentProviderClient contentProviderClient = getContentProviderClient();
        try {
            if (mimetypeString.startsWith("image/")) {
                // Images
                contentProviderClient.delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                        MediaStore.Images.Media.DATA + "=?", new String[] { path });
            } else if (mimetypeString.startsWith("audio/")) {
                // Audio
                contentProviderClient.delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                        MediaStore.Audio.Media.DATA + "=?", new String[] { path });
            } else if (mimetypeString.startsWith("video/")) {
                // Video
                contentProviderClient.delete(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
                        MediaStore.Video.Media.DATA + "=?", new String[] { path });
            }
        } catch (RemoteException e) {
            Log_OC.e(TAG, "Exception deleting media file in MediaStore " + e.getMessage());
        }
    }

}

From source file:info.dc585.hpt.sa.SyncAdapter.java

private void syncTopHackers(ContentProviderClient provider, SyncResult syncResult) {

    try {/*from  w w  w. j  a  va  2 s.com*/

        Log.d(TAG, "Calling something to sync up hackerpoint db");

        JSONArray hackers = NetworkUtilities.getTopHackers();
        if (hackers == null) {
            Log.e(TAG, "somehow got null hackers, explode please");
            syncResult.stats.numParseExceptions++;
        }
        if (hackers.length() == 0) {
            return;
        }

        Log.i(TAG, "Updateing content provider");
        Log.i(TAG, "hackers.length():" + hackers.length());
        for (int i = 0; i < hackers.length(); i++) {
            JSONObject jo = hackers.getJSONObject(i);
            String name = jo.getString("name");

            String selection = TopHackerTable.COLUMN_NAME + " like ?";
            String[] selectionArgs = { name };

            String[] projection = { TopHackerTable.COLUMN_ID, TopHackerTable.COLUMN_NAME };

            ContentValues values = new ContentValues();

            // FIXME:  Dear self, WTF would i trust network returned data without verifying limits ;)
            // TODO: See FIXME above.
            Cursor c = provider.query(HackerPointsContentProvider.HACKERS_URI, projection, selection,
                    selectionArgs, null);
            if (c.getCount() == 0) {
                Log.d(TAG, "performing insert for new name:" + name);

                int points = jo.getInt("points");
                values.put(TopHackerTable.COLUMN_POINTS, points);

                int pool = jo.getInt("pool");
                values.put(TopHackerTable.COLUMN_POOL, pool);

                int internets = jo.getInt("internets");
                values.put(TopHackerTable.COLUMN_INTERNETS, internets);

                String pictureURL = jo.getString("pictureURL");
                values.put(TopHackerTable.COLUMN_PICTUREURL, pictureURL);

                values.put(TopHackerTable.COLUMN_NAME, name);
                values.put(TopHackerTable.COLUMN_UPDATE, System.currentTimeMillis());
                provider.insert(HackerPointsContentProvider.HACKERS_URI, values);
                syncResult.stats.numInserts++;

            } else if (c.getCount() == 1) {
                Log.d(TAG, "performing update for name:" + name);
                if (name == null || name.isEmpty()) {
                    Log.e(TAG, "null or empty name");
                    continue;
                }

                int points = jo.getInt("points");
                values.put(TopHackerTable.COLUMN_POINTS, points);

                int pool = jo.getInt("pool");
                values.put(TopHackerTable.COLUMN_POOL, pool);

                int internets = jo.getInt("internets");
                values.put(TopHackerTable.COLUMN_INTERNETS, internets);

                String pictureURL = jo.getString("pictureURL");
                values.put(TopHackerTable.COLUMN_PICTUREURL, pictureURL);

                int rows = provider.update(HackerPointsContentProvider.HACKERS_URI, values, selection,
                        selectionArgs);

                Log.d(TAG, "Updated:" + rows + ": rows");
                syncResult.stats.numUpdates += rows;

            } else {
                Log.e(TAG, "Cursor count was not 0 or 1 was:" + c.getCount());
                continue;
            }
        }

        // Now run through both lists and figure out which one to delete.
        String[] projection = { TopHackerTable.COLUMN_NAME };
        Cursor c = provider.query(HackerPointsContentProvider.HACKERS_URI, projection, null, null, null);
        if (c.getCount() == 0) {
            return;
        }

        ArrayList<String> goodNames = new ArrayList<String>();
        ArrayList<String> rmNames = new ArrayList<String>();

        for (int i = 0; i < hackers.length(); i++) {
            JSONObject jo = hackers.getJSONObject(i);
            String name = jo.getString("name");
            goodNames.add(name);
        }

        while (c.moveToNext()) {
            int namec = c.getColumnIndex(TopHackerTable.COLUMN_NAME);
            String dbName = c.getString(namec);

            if (goodNames.contains(dbName) == false) {
                Log.d(TAG, "Adding name:" + dbName + ": to the delete list");
                rmNames.add(dbName);
            }
        }

        for (String nextName : rmNames) {
            Log.d(TAG, "deleting name:" + nextName + ":");
            // FIXME: use column name from Table class
            String where = " name = ? ";
            String[] whereArgs = { nextName };
            int rows = provider.delete(HackerPointsContentProvider.HACKERS_URI, where, whereArgs);
            syncResult.stats.numDeletes += rows;
        }

    } catch (final AuthenticationException e) {
        Log.e(TAG, "AuthenticationException", e);
    } catch (final JSONException e) {
        Log.e(TAG, "JSONException", e);
    } catch (final IOException e) {
        Log.e(TAG, "IOException", e);
    } catch (final ParseException e) {
        Log.e(TAG, "ParseException", e);
        syncResult.stats.numParseExceptions++;
    } catch (final RemoteException e) {
        Log.e(TAG, "RemoteException", e);
    }
}

From source file:org.gege.caldavsyncadapter.syncadapter.SyncAdapter.java

/**
 * checks the android events for the dirty flag.
 * the flag is set by android when the event has been changed. 
 * the dirty flag is removed when an android event has been updated from calendar event
 * @param provider/*from  ww  w .j av a  2s.com*/
 * @param account
 * @param calendarUri
 * @param facade
 * @param caldavCalendarUri
 * @param stats
 * @param notifyList
 * @return count of dirty events
 */
private int checkDirtyAndroidEvents(ContentProviderClient provider, Account account, Uri calendarUri,
        CaldavFacade facade, URI caldavCalendarUri, SyncStats stats, ArrayList<Uri> notifyList) {
    Cursor curEvent = null;
    Cursor curAttendee = null;
    Cursor curReminder = null;
    Long EventID;
    Long CalendarID;
    AndroidEvent androidEvent = null;
    int rowDirty = 0;
    int rowInsert = 0;
    int rowUpdate = 0;
    int rowDelete = 0;

    try {
        CalendarID = ContentUris.parseId(calendarUri);
        String selection = "(" + Events.DIRTY + " = ?) AND (" + Events.CALENDAR_ID + " = ?)";
        String[] selectionArgs = new String[] { "1", CalendarID.toString() };
        curEvent = provider.query(Events.CONTENT_URI, null, selection, selectionArgs, null);

        while (curEvent.moveToNext()) {
            EventID = curEvent.getLong(curEvent.getColumnIndex(Events._ID));
            Uri returnedUri = ContentUris.withAppendedId(Events.CONTENT_URI, EventID);

            androidEvent = new AndroidEvent(account, provider, returnedUri, calendarUri);
            androidEvent.readContentValues(curEvent);

            selection = "(" + Attendees.EVENT_ID + " = ?)";
            selectionArgs = new String[] { String.valueOf(EventID) };
            curAttendee = provider.query(Attendees.CONTENT_URI, null, selection, selectionArgs, null);
            selection = "(" + Reminders.EVENT_ID + " = ?)";
            selectionArgs = new String[] { String.valueOf(EventID) };
            curReminder = provider.query(Reminders.CONTENT_URI, null, selection, selectionArgs, null);
            androidEvent.readAttendees(curAttendee);
            androidEvent.readReminder(curReminder);
            curAttendee.close();
            curReminder.close();

            String SyncID = androidEvent.ContentValues.getAsString(Events._SYNC_ID);

            boolean Deleted = false;
            int intDeleted = 0;
            intDeleted = curEvent.getInt(curEvent.getColumnIndex(Events.DELETED));
            Deleted = (intDeleted == 1);

            if (SyncID == null) {
                // new Android event
                String newGUID = java.util.UUID.randomUUID().toString() + "-caldavsyncadapter";
                String calendarPath = caldavCalendarUri.getPath();
                if (!calendarPath.endsWith("/"))
                    calendarPath += "/";

                SyncID = calendarPath + newGUID + ".ics";

                androidEvent.createIcs(newGUID);

                if (facade.createEvent(URI.create(SyncID), androidEvent.getIcsEvent().toString())) {
                    //HINT: bugfix for google calendar
                    if (SyncID.contains("@"))
                        SyncID = SyncID.replace("@", "%40");
                    ContentValues values = new ContentValues();
                    values.put(Events._SYNC_ID, SyncID);

                    //google doesn't send the etag after creation
                    //HINT: my SabreDAV send always the same etag after putting a new event
                    //String LastETag = facade.getLastETag();
                    //if (!LastETag.equals("")) {
                    //   values.put(Event.ETAG, LastETag);
                    //} else {
                    //so get the etag with a new REPORT
                    CalendarEvent calendarEvent = new CalendarEvent(account, provider);
                    calendarEvent.calendarURL = caldavCalendarUri.toURL();
                    URI SyncURI = new URI(SyncID);
                    calendarEvent.setUri(SyncURI);
                    CaldavFacade.getEvent(calendarEvent);
                    values.put(Event.ETAG, calendarEvent.getETag());
                    //}
                    values.put(Event.UID, newGUID);
                    values.put(Events.DIRTY, 0);
                    values.put(Event.RAWDATA, androidEvent.getIcsEvent().toString());

                    int rowCount = provider.update(
                            asSyncAdapter(androidEvent.getUri(), account.name, account.type), values, null,
                            null);
                    if (rowCount == 1) {
                        rowInsert += 1;
                        notifyList.add(androidEvent.getUri());
                    }
                }
            } else if (Deleted) {
                // deleted Android event
                if (facade.deleteEvent(URI.create(SyncID), androidEvent.getETag())) {
                    String mSelectionClause = "(" + Events._ID + "= ?)";
                    String[] mSelectionArgs = { String.valueOf(EventID) };

                    int countDeleted = provider.delete(
                            asSyncAdapter(Events.CONTENT_URI, account.name, account.type), mSelectionClause,
                            mSelectionArgs);

                    if (countDeleted == 1) {
                        rowDelete += 1;
                        notifyList.add(androidEvent.getUri());
                    }
                }
            } else {
                //update the android event to the server
                String uid = androidEvent.getUID();
                if ((uid == null) || (uid.equals(""))) {
                    //COMPAT: this is needed because in the past, the UID was not stored in the android event
                    CalendarEvent calendarEvent = new CalendarEvent(account, provider);
                    URI syncURI = new URI(SyncID);
                    calendarEvent.setUri(syncURI);
                    calendarEvent.calendarURL = caldavCalendarUri.toURL();
                    if (calendarEvent.fetchBody()) {
                        calendarEvent.readContentValues();
                        uid = calendarEvent.getUID();
                    }
                }
                if (uid != null) {
                    androidEvent.createIcs(uid);

                    if (facade.updateEvent(URI.create(SyncID), androidEvent.getIcsEvent().toString(),
                            androidEvent.getETag())) {
                        selection = "(" + Events._ID + "= ?)";
                        selectionArgs = new String[] { EventID.toString() };
                        androidEvent.ContentValues.put(Events.DIRTY, 0);

                        //google doesn't send the etag after update
                        String LastETag = facade.getLastETag();
                        if (!LastETag.equals("")) {
                            androidEvent.ContentValues.put(Event.ETAG, LastETag);
                        } else {
                            //so get the etag with a new REPORT
                            CalendarEvent calendarEvent = new CalendarEvent(account, provider);
                            calendarEvent.calendarURL = caldavCalendarUri.toURL();
                            URI SyncURI = new URI(SyncID);
                            calendarEvent.setUri(SyncURI);
                            CaldavFacade.getEvent(calendarEvent);
                            androidEvent.ContentValues.put(Event.ETAG, calendarEvent.getETag());
                        }
                        androidEvent.ContentValues.put(Event.RAWDATA, androidEvent.getIcsEvent().toString());
                        int RowCount = provider.update(
                                asSyncAdapter(androidEvent.getUri(), account.name, account.type),
                                androidEvent.ContentValues, null, null);

                        if (RowCount == 1) {
                            rowUpdate += 1;
                            notifyList.add(androidEvent.getUri());
                        }
                    } else {
                        rowDirty += 1;
                    }
                } else {
                    rowDirty += 1;
                }
            }
        }
        curEvent.close();

        /*if ((rowInsert > 0) || (rowUpdate > 0) || (rowDelete > 0) || (rowDirty > 0)) {
           Log.i(TAG,"Android Rows inserted: " + String.valueOf(rowInsert));
           Log.i(TAG,"Android Rows updated:  " + String.valueOf(rowUpdate));
           Log.i(TAG,"Android Rows deleted:  " + String.valueOf(rowDelete));
           Log.i(TAG,"Android Rows dirty:    " + String.valueOf(rowDirty));
        }*/

        stats.numInserts += rowInsert;
        stats.numUpdates += rowUpdate;
        stats.numDeletes += rowDelete;
        stats.numSkippedEntries += rowDirty;
        stats.numEntries += rowInsert + rowUpdate + rowDelete;
    } catch (RemoteException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        // TODO Automatisch generierter Erfassungsblock
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO Automatisch generierter Erfassungsblock
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Automatisch generierter Erfassungsblock
        e.printStackTrace();
    } catch (CaldavProtocolException e) {
        // TODO Automatisch generierter Erfassungsblock
        e.printStackTrace();
    } catch (ParserException e) {
        // TODO Automatisch generierter Erfassungsblock
        e.printStackTrace();
    }

    return rowDirty;
}

From source file:com.snu.msl.sensys.SyncAdapter.SyncAdapter.java

@Override
public void onPerformSync(Account account, Bundle bundle, String s, ContentProviderClient contentProviderClient,
        SyncResult syncResult) {/*from  w ww .j av  a 2  s.  com*/
    Log.d("UPUP", "Reached here");
    try {
        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();
    }

}