Android: Content resolver query returning 0 rows when it ought not to

前端 未结 2 506
野性不改
野性不改 2021-01-07 07:34
Cursor cursor = resolver.query(
    Data.CONTENT_URI,
    DataQuery.PROJECTION,
    DataQuery.SELECTION,
    new String[] {String.valueOf(rawContactId)},
    null);
         


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-01-07 07:41

    There are a few issues that i could locate with the following query:

    Cursor cursor = resolver.query(Data.CONTENT_URI, 
                                   UserIdQuery.PROJECTION, 
                                   UserIdQuery.SELECTION, 
                                   new String[] {username}, null);
    
    1. If all the columns are pointing out at RawContacts table then you should use RawContacts.CONTENT_URI instead of Data.CONTENT_URI.
    2. Here the value of RawContacts.SOURCE_ID is compared with username

      public static final String SELECTION = RawContacts.ACCOUNT_TYPE + "='" + 
              "com.tagapp.android" + "' AND " + RawContacts.SOURCE_ID + "=?";
      
      new String[] {username}
      

提交回复
热议问题