2011-08-09 7 views
0

サンプルの連絡先:
_IDのDISPLAY_NAMEのPHONE I挿入しようとしている
1 contact1 11111111
2 contact2 22222222挿入指定した連絡先へのStatusUpdatesが、常にランダムな接触に挿入

Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode("22222222")); 
Cursor c = this.getContentResolver().query(uri, new String[] {Data._ID}, null, null, null); 
long profileId = 0; 
if (c.moveToFirst()) 
{ 
    profileId = c.getLong(0); 
} 
c.close(); 
c = null; 

final ContentValues values = new ContentValues(); 

if (profileId > 0) { 
    values.put(StatusUpdates.DATA_ID, profileId); 
    values.put(StatusUpdates.STATUS, "HELLO WORLD!"); 
    values.put(StatusUpdates.PROTOCOL, Im.PROTOCOL_CUSTOM); 
    values.put(StatusUpdates.CUSTOM_PROTOCOL, CUSTOM_IM_PROTOCOL); 
    values.put(StatusUpdates.PRESENCE, 4); // 
    values.put(StatusUpdates.STATUS_RES_PACKAGE, this.getPackageName()); 
    values.put(StatusUpdates.STATUS_LABEL, R.string.label); 

    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); 
    ops.add(ContentProviderOperation.newInsert(StatusUpdates.CONTENT_URI) 
      .withValues(values).build()); 

    try{ 
     this.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 
    } 
    catch(RemoteException e) 
    {Log.e...} 
    catch(OperationApplicationException e) 
    {Log.e...} 
} 

ステータスは指定された連絡先 "contact2"に送信されますが、正しく動作せず、常に "contact1"に挿入されます。

私は多くのおかげで助けてください。サンプル同期アダプタの例から

答えて

0

public static long lookupRawContact(ContentResolver resolver, String userId) 
{ 
    long authorId = 0; 
    final Cursor c = 
      resolver.query(RawContacts.CONTENT_URI, UserIdQuery.PROJECTION, 
        UserIdQuery.SELECTION, new String[] {userId}, 
        null); 
    try { 
     if (c.moveToFirst()) { 
      authorId = c.getLong(UserIdQuery.COLUMN_ID); 
     } 
    } finally { 
     if (c != null) { 
      c.close(); 
     } 
    } 
    return authorId; 
} 

を見つけていない場合、これは正しいプロファイルIDまたは0を返します。
関連する問題