Getting Raw ID from ID

The following code worked fine two days ago, but suddenly - I did not do what happened - the code behaves abnormally, it gives the result as ID and RawId. For example:

Id =356
RawId = 356

I struggled to understand what was happening, unsuccessfully. Any ideas on how to fix this?

String projection[]=new String[]{ContactsContract.RawContacts._ID};
                      String where=ContactsContract.RawContacts.CONTACT_ID+"=?";
                      String selectionArgs[]=new String[]{String.valueOf(id)};
                      CursorLoader cLoader=new CursorLoader(this,ContactsContract.RawContacts.CONTENT_URI,projection,where,selectionArgs,null);
                      Cursor c=cLoader.loadInBackground();
                      c.moveToFirst();
                      rawContactID=c.getString(c.getColumnIndex(ContactsContract.RawContacts._ID));
                      Toast.makeText(getBaseContext(),"Id = "+id+" \nRaw id = "+rawContactID,Toast.LENGTH_SHORT).show();
+4
source share
1 answer

try it

public int getRawContactId(int contactId) {
    String[] projection = new String[]{ContactsContract.RawContacts._ID};
    String selection = ContactsContract.RawContacts.CONTACT_ID + "=?";
    String[] selectionArgs = new String[]{String.valueOf(contactId)};
    Cursor c = getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI, projection, selection, selectionArgs, null);
    c.moveToNext();
    int rawContactId = c.getInt(c.getColumnIndex(ContactsContract.RawContacts._ID));
    return rawContactId;
}
0
source

All Articles