Example usage for android.database Cursor getColumnIndex

List of usage examples for android.database Cursor getColumnIndex

Introduction

In this page you can find the example usage for android.database Cursor getColumnIndex.

Prototype

int getColumnIndex(String columnName);

Source Link

Document

Returns the zero-based index for the given column name, or -1 if the column doesn't exist.

Usage

From source file:com.jaspersoft.android.jaspermobile.activities.profile.fragment.ServersFragment.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    JasperMobileApplication.removeAllCookies();

    Cursor cursor = mAdapter.getCursor();
    cursor.moveToPosition(position);//  w  w w. j  a va2 s.  c om

    JsServerProfile oldProfile = jsRestClient.getServerProfile();
    long profileId = cursor.getLong(cursor.getColumnIndex(ServerProfilesTable._ID));

    boolean isSameCurrentProfileSelected = (oldProfile != null && oldProfile.getId() == profileId);

    if (isSameCurrentProfileSelected) {
        setResultOk(profileId);
    } else {
        JsServerProfile newProfile = profileHelper.createProfileFromCursor(cursor);
        String password = newProfile.getPassword();

        boolean alwaysAskPassword = TextUtils.isEmpty(password);
        if (alwaysAskPassword) {
            setResultOk(profileId);
        } else {
            JsRestClient tmpRestClient = new JsRestClient();
            tmpRestClient.setConnectTimeout(prefHelper.getConnectTimeoutValue());
            tmpRestClient.setReadTimeout(prefHelper.getReadTimeoutValue());
            tmpRestClient.setServerProfile(newProfile);

            GetServerInfoRequest request = new GetServerInfoRequest(tmpRestClient);
            request.setRetryPolicy(null);

            setRefreshActionState(true);
            getSpiceManager().execute(new GetServerInfoRequest(tmpRestClient),
                    new ValidateServerInfoListener(newProfile));
        }
    }
}

From source file:com.jaspersoft.android.jaspermobile.util.SavedItemHelper.java

public void deleteUnsavedItems() {
    String selection = SavedItemsTable.DOWNLOADED + " =?";
    Cursor cursor = context.getContentResolver().query(MobileDbProvider.SAVED_ITEMS_CONTENT_URI,
            new String[] { SavedItemsTable._ID, SavedItemsTable.FILE_PATH }, selection, new String[] { "0" },
            null);//from   ww w .j  a  va2 s.co m

    if (cursor == null)
        return;

    if (cursor.moveToFirst()) {
        do {
            int id = cursor.getInt(cursor.getColumnIndex(SavedItemsTable._ID));
            Uri uri = Uri.withAppendedPath(JasperMobileDbProvider.SAVED_ITEMS_CONTENT_URI, String.valueOf(id));
            deleteSavedItem(uri);
        } while (cursor.moveToNext());
    }

    cursor.close();
}

From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java

/**
 * @param/*from  w ww.  j a va 2s.  co m*/
 */
public static void deleteLocalFileAfterFire(String msgId) {

    if (TextUtils.isEmpty(msgId)) {
        return;
    }
    String text = "";
    String sql = "select * from " + DatabaseHelper.TABLES_NAME_IM_MESSAGE + " where msgid = '" + msgId + "'";
    Cursor cursor = getInstance().sqliteDB().rawQuery(sql, null);
    if (cursor != null && cursor.getCount() > 0) {
        if (cursor.moveToFirst()) {
            text = cursor.getString(cursor.getColumnIndex("localPath"));
            cursor.close();
            cursor = null;

        }
    }

    if (!TextUtils.isEmpty(text)) {

        File file = new File(text);
        if (file != null && file.exists()) {
            file.delete();
        }
    }

}

From source file:net.fluidnexus.FluidNexusAndroid.services.NexusServiceThread.java

/**
 * Start the listeners for zeroconf services
 *//*  w w  w  .  java  2 s  . co  m*/
public void doStateNone() {
    if (wifiManager.getWifiState() == wifiManager.WIFI_STATE_ENABLED) {
        Cursor c = messagesProviderHelper.publicMessages();

        while (c.isAfterLast() == false) {
            String message_hash = c.getString(c.getColumnIndex(MessagesProviderHelper.KEY_MESSAGE_HASH));
            boolean result = checkHash(message_hash);

            if (!result) {
                try {
                    JSONObject message = new JSONObject();
                    message.put("message_title",
                            c.getString(c.getColumnIndex(MessagesProviderHelper.KEY_TITLE)));
                    message.put("message_content",
                            c.getString(c.getColumnIndex(MessagesProviderHelper.KEY_CONTENT)));
                    message.put("message_hash",
                            c.getString(c.getColumnIndex(MessagesProviderHelper.KEY_MESSAGE_HASH)));
                    message.put("message_type", c.getInt(c.getColumnIndex(MessagesProviderHelper.KEY_TYPE)));
                    message.put("message_time", c.getFloat(c.getColumnIndex(MessagesProviderHelper.KEY_TIME)));
                    message.put("message_received_time",
                            c.getFloat(c.getColumnIndex(MessagesProviderHelper.KEY_RECEIVED_TIME)));
                    message.put("message_priority",
                            c.getInt(c.getColumnIndex(MessagesProviderHelper.KEY_PRIORITY)));

                    String attachment_path = c
                            .getString(c.getColumnIndex(MessagesProviderHelper.KEY_ATTACHMENT_PATH));

                    //String serializedMessage = message.toString();

                    // First, get our nonce
                    consumer = new CommonsHttpOAuthConsumer(key, secret);
                    consumer.setTokenWithSecret(token, token_secret);
                    HttpPost nonce_request = new HttpPost(NEXUS_NONCE_URL);
                    consumer.sign(nonce_request);
                    HttpClient client = new DefaultHttpClient();
                    String response = client.execute(nonce_request, new BasicResponseHandler());
                    JSONObject object = new JSONObject(response);
                    String nonce = object.getString("nonce");

                    // Then, take our nonce and key and put them in the message
                    message.put("message_nonce", nonce);
                    message.put("message_key", key);

                    // Setup our multipart entity
                    MultipartEntity entity = new MultipartEntity();

                    // Deal with file attachment
                    if (!attachment_path.equals("")) {
                        File file = new File(attachment_path);
                        ContentBody cbFile = new FileBody(file);
                        entity.addPart("message_attachment", cbFile);

                        // add the original filename to the message
                        message.put("message_attachment_original_filename", c.getString(
                                c.getColumnIndex(MessagesProviderHelper.KEY_ATTACHMENT_ORIGINAL_FILENAME)));
                    }

                    String serializedMessage = message.toString();
                    ContentBody messageBody = new StringBody(serializedMessage);
                    entity.addPart("message", messageBody);

                    HttpPost message_request = new HttpPost(NEXUS_MESSAGE_URL);
                    message_request.setEntity(entity);

                    client = new DefaultHttpClient();
                    client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

                    response = client.execute(message_request, new BasicResponseHandler());
                    object = new JSONObject(response);
                    boolean message_result = object.getBoolean("result");

                    if (message_result) {
                        ContentValues values = new ContentValues();
                        values.put(MessagesProviderHelper.KEY_MESSAGE_HASH, message_hash);
                        values.put(MessagesProviderHelper.KEY_UPLOADED, 1);
                        int res = messagesProviderHelper
                                .setPublic(c.getLong(c.getColumnIndex(MessagesProviderHelper.KEY_ID)), values);
                        if (res == 0) {
                            log.debug("Message with hash " + message_hash
                                    + " not found; this should never happen!");
                        }
                    }

                } catch (OAuthMessageSignerException e) {
                    log.debug("OAuthMessageSignerException: " + e);
                } catch (OAuthExpectationFailedException e) {
                    log.debug("OAuthExpectationFailedException: " + e);
                } catch (OAuthCommunicationException e) {
                    log.debug("OAuthCommunicationException: " + e);
                } catch (JSONException e) {
                    log.debug("JSON Error: " + e);
                } catch (IOException e) {
                    log.debug("IOException: " + e);
                }
            }
            c.moveToNext();
        }

        c.close();

    }

    setServiceState(STATE_SERVICE_WAIT);
}

From source file:com.crankworks.cycletracks.TripUploader.java

private JSONObject getCoordsJSON(long tripId) throws JSONException {
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    mDb.openReadOnly();//from   w w w .  ja  va  2  s .  c  o m
    Cursor tripCoordsCursor = mDb.fetchAllCoordsForTrip(tripId);

    // Build the map between JSON fieldname and phone db fieldname:
    Map<String, Integer> fieldMap = new HashMap<String, Integer>();
    fieldMap.put(TRIP_COORDS_TIME, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_TIME));
    fieldMap.put(TRIP_COORDS_LAT, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_LAT));
    fieldMap.put(TRIP_COORDS_LON, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_LGT));
    fieldMap.put(TRIP_COORDS_ALT, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_ALT));
    fieldMap.put(TRIP_COORDS_SPEED, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_SPEED));
    fieldMap.put(TRIP_COORDS_HACCURACY, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_ACC));
    fieldMap.put(TRIP_COORDS_VACCURACY, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_ACC));

    // Build JSON objects for each coordinate:
    JSONObject tripCoords = new JSONObject();
    while (!tripCoordsCursor.isAfterLast()) {
        JSONObject coord = new JSONObject();

        coord.put(TRIP_COORDS_TIME, df.format(tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_TIME))));
        coord.put(TRIP_COORDS_LAT, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_LAT)) / 1E6);
        coord.put(TRIP_COORDS_LON, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_LON)) / 1E6);
        coord.put(TRIP_COORDS_ALT, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_ALT)));
        coord.put(TRIP_COORDS_SPEED, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_SPEED)));
        coord.put(TRIP_COORDS_HACCURACY, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_HACCURACY)));
        coord.put(TRIP_COORDS_VACCURACY, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_VACCURACY)));

        tripCoords.put(coord.getString("rec"), coord);
        tripCoordsCursor.moveToNext();
    }
    tripCoordsCursor.close();
    mDb.close();
    return tripCoords;
}

From source file:src.com.nustats.pacelogger.TripUploader.java

private JSONObject getCoordsJSON(long tripId) throws JSONException {
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");

    mDb.openReadOnly();//from  w ww . ja  v  a 2 s .  c o m
    Cursor tripCoordsCursor = mDb.fetchAllCoordsForTrip(tripId);

    // Build the map between JSON fieldname and phone db fieldname:
    Map<String, Integer> fieldMap = new HashMap<String, Integer>();
    fieldMap.put(TRIP_COORDS_TIME, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_TIME));
    fieldMap.put(TRIP_COORDS_LAT, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_LAT));
    fieldMap.put(TRIP_COORDS_LON, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_LGT));
    fieldMap.put(TRIP_COORDS_ALT, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_ALT));
    fieldMap.put(TRIP_COORDS_SPEED, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_SPEED));
    fieldMap.put(TRIP_COORDS_HACCURACY, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_ACC));
    fieldMap.put(TRIP_COORDS_VACCURACY, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_ACC));

    // Build JSON objects for each coordinate:
    JSONObject tripCoords = new JSONObject();
    while (!tripCoordsCursor.isAfterLast()) {
        JSONObject coord = new JSONObject();

        coord.put(TRIP_COORDS_TIME, df.format(tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_TIME))));
        coord.put(TRIP_COORDS_LAT, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_LAT)) / 1E6);
        coord.put(TRIP_COORDS_LON, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_LON)) / 1E6);
        coord.put(TRIP_COORDS_ALT, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_ALT)));
        coord.put(TRIP_COORDS_SPEED, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_SPEED)));
        coord.put(TRIP_COORDS_HACCURACY, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_HACCURACY)));
        coord.put(TRIP_COORDS_VACCURACY, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_VACCURACY)));

        tripCoords.put(coord.getString("rec"), coord);
        tripCoordsCursor.moveToNext();
    }
    tripCoordsCursor.close();
    mDb.close();
    return tripCoords;
}

From source file:com.digipom.manteresting.android.processor.json.NailsJsonProcessor.java

@Override
public ArrayList<ContentProviderOperation> parse(JSONObject response, Meta meta) throws JSONException {
    final ArrayList<ContentProviderOperation> batch = Lists.newArrayList();
    final TreeSet<Integer> nailIds = new TreeSet<Integer>();
    final Cursor nails = resolver.query(ManterestingContract.Nails.CONTENT_URI, new String[] { Nails.NAIL_ID },
            null, null, Nails.NAIL_ID + " DESC");
    int greatestOfExisting = Integer.MIN_VALUE;

    if (nails != null && !nails.isClosed()) {
        try {/*from  www  .  j  av  a  2  s .  c  o  m*/
            nails.moveToFirst();

            final int idColumn = nails.getColumnIndex(Nails.NAIL_ID);

            while (!nails.isAfterLast()) {
                final int nailId = nails.getInt(idColumn);
                nailIds.add(nailId);
                greatestOfExisting = nailId > greatestOfExisting ? nailId : greatestOfExisting;
                nails.moveToNext();
            }
        } finally {
            if (nails != null) {
                nails.close();
            }
        }
    }

    final JSONArray objects = response.getJSONArray("objects");
    int smallestOfNew = Integer.MAX_VALUE;

    for (int i = 0; i < objects.length(); i++) {
        final JSONObject nailObject = objects.getJSONObject(i);

        final boolean isPrivate = nailObject.getJSONObject("workbench").getBoolean("private");

        if (!isPrivate) {
            final ContentProviderOperation.Builder builder = ContentProviderOperation
                    .newInsert(Nails.CONTENT_URI);
            final int nailId = nailObject.getInt("id");
            smallestOfNew = nailId < smallestOfNew ? nailId : smallestOfNew;

            builder.withValue(Nails.NAIL_ID, nailId);
            builder.withValue(Nails.NAIL_JSON, nailObject.toString());

            batch.add(builder.build());
            nailIds.add(nailId);
        }
    }

    // If more than LIMIT were fetched, and this was the initial fetch, then
    // we flush everything in the DB before adding the new nails (as
    // otherwise we would introduce a gap).
    if (meta.nextOffset == meta.nextLimit // For initial fetch
            && smallestOfNew > greatestOfExisting) {
        if (LoggerConfig.canLog(Log.DEBUG)) {
            Log.d(TAG, "Flushing all existing nails on initial fetch, so as to avoid a gap.");
        }

        resolver.delete(Nails.CONTENT_URI, null, null);
    } else {
        // If more than 500 nails, find the 500th biggest and delete those
        // after it.
        if (nailIds.size() > MAX_COUNT) {
            Iterator<Integer> it = nailIds.descendingIterator();

            for (int i = 0; i < MAX_COUNT; i++) {
                it.next();
            }

            final Integer toDelete = it.next();

            if (LoggerConfig.canLog(Log.DEBUG)) {
                Log.d(TAG, "deleting from nails where NAIL_ID is less than or equal to " + toDelete);
            }

            SelectionBuilder selectionBuilder = new SelectionBuilder();
            selectionBuilder.where(ManterestingContract.Nails.NAIL_ID + " <= ?",
                    new String[] { String.valueOf(toDelete) });
            resolver.delete(ManterestingContract.Nails.CONTENT_URI, selectionBuilder.getSelection(),
                    selectionBuilder.getSelectionArgs());
        }
    }

    return batch;
}

From source file:com.google.cloud.solutions.smashpix.MainActivity.java

  public String getPathFromData(Uri uri) {
  try {//from www .j  av  a  2  s. c o  m
    String[] filePathData = {MediaStore.Images.Media.DATA};
    Cursor cursor = getContentResolver().query(uri, filePathData, null, null, null);
    cursor.moveToFirst();
    int dataColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
    String picturePath = cursor.getString(dataColumnIndex);
    cursor.close();
    return picturePath;
  } catch (Exception e) {
    Log.e(Constants.APP_NAME, e.getMessage());
  }
  return uri.getPath();
}

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  w  w .  jav  a 2  s.  c o  m*/
    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();
    }

}

From source file:com.openerp.base.res.Res_PartnerSyncHelper.java

public Uri getPartnerUri(int partner_id) {
    Account account = OpenERPAccountManager.getAccount(mContext, OEUser.current(mContext).getAndroidName());
    Uri rawContactUri = RawContacts.CONTENT_URI.buildUpon()
            .appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name)
            .appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type).build();

    mContentResolver = mContext.getContentResolver();
    Cursor data = mContentResolver.query(rawContactUri, null, SYNC1_PARTNER_ID + " = " + partner_id, null,
            null);//w w w.jav a2s .  c om
    String contact_raw_id = null;
    while (data.moveToNext()) {
        contact_raw_id = data.getString(data.getColumnIndex(ContactsContract.Contacts._ID));
    }
    data.close();

    Uri contact_uri = null;
    if (contact_raw_id != null) {
        contact_uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, contact_raw_id);
    }
    return contact_uri;
}