Im einige Änderungen an einer App zu machen versuchen, die ich heruntergeladen habe, die App ContactContracts verwendet die Liste der Kontakte im Telefon gespeichert zu zeigen,Ein Content-Provider zu ersetzen ContactcsContract
, was im zu tun versuchen, ist mit ein Content-Provider eine Liste von Kontakten zu zeigen, dass ich in meiner Datenbank
die ursprüngliche App nutzt diese Methode gespeichert habe Kontakte aus dem Telefon zu laden und zu speichern, die in „Kontakt“ Objekt:
public void loadContactsData(){
if(SmsSchedulerApplication.contactsList.size()==0){
System.currentTimeMillis();
String[] projection = new String[] {Groups._ID};
Uri groupsUri = ContactsContract.Groups.CONTENT_URI;
groupCursor = managedQuery(groupsUri, projection, null, null, null);
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if(cursor.moveToFirst()){
do{
if(!(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)).equals("0"))){
String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
Cursor phones = cr.query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + " = " + id, null, null);
if(phones.moveToFirst()){
Contact contact = new Contact();
contact.content_uri_id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
contact.name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
contact.number = phones.getString(phones.getColumnIndex(Phone.NUMBER));
Cursor cur = cr.query(ContactsContract.Data.CONTENT_URI, new String[]{ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID}, ContactsContract.CommonDataKinds.GroupMembership.CONTACT_ID + "=" + contact.content_uri_id, null, null);
if(cur.moveToFirst()){
do{
if(!String.valueOf(cur.getLong(cur.getColumnIndex(ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID))).equals(contact.number) && cur.getLong(cur.getColumnIndex(ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID))!=0){
boolean isValid = false;
if(groupCursor.moveToFirst()){
do{
if(!cur.isClosed() && !groupCursor.isClosed() && cur.getLong(cur.getColumnIndex(ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID)) == groupCursor.getLong(groupCursor.getColumnIndex(Groups._ID))){
isValid = true;
break;
}
}while(groupCursor.moveToNext());
}
if(isValid){
contact.groupRowId.add(cur.getLong(cur.getColumnIndex(ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID)));
}
}
}while(cur.moveToNext());
}
cur.close();
Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(contact.content_uri_id));
InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(cr, uri);
try{
contact.image = BitmapFactory.decodeStream(input);
contact.image.getHeight();
} catch (NullPointerException e){
contact.image = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.no_image_thumbnail);
}
SmsSchedulerApplication.contactsList.add(contact);
}
}
}while(cursor.moveToNext());
}
}
}
im nicht vertraut mit der Verwendung von Content-Provider, so bin ich nicht Was sollte ich in meiner Content-Provider-Klasse definieren?