以下代码在两天前完美运行,但突然 - 我不会发生什么 - 代码行为异常,它提供输出ID和RawId
相同。例如:
Id =356
RawId = 356
我尽力知道是什么事,不成功。关于如何解决它的任何想法?
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();
答案 0 :(得分:0)
试试这个
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;
}