我正在制作Android应用,需要拨打电话的联系人列表.我需要调用联系人列表功能,选择联系人,然后使用联系人姓名返回我的应用程序.这是我在互联网上获得的代码,但它不起作用.
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
public class Contacts extends ListActivity {
private ListAdapter mAdapter;
public TextView pbContact;
public static String PBCONTACT;
public static final int ACTIVITY_EDIT=1;
private static final int ACTIVITY_CREATE=0;
// Called when the activity is first created.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Cursor C = getContentResolver().query(People.CONTENT_URI, null, null, null, null);
startManagingCursor(C);
String[] columns = new String[] {People.NAME};
int[] names = …Run Code Online (Sandbox Code Playgroud) 我试图通过电话获得whatsapp联系,我得到whatsapp联系的总数,但是从RawContacts如何获得whatsapp我不知道的号码和名称.我试图找到解决方案,但无法得到确切的解决方案.请帮我.
我把我的代码放在下面.
ContentResolver cr = context.getContentResolver();
Cursor c = cr.query(
ContactsContract.RawContacts.CONTENT_URI,
new String[] { ContactsContract.RawContacts.CONTACT_ID, ContactsContract.RawContacts.DISPLAY_NAME_PRIMARY },
ContactsContract.RawContacts.ACCOUNT_TYPE + "= ?",
new String[] { "com.whatsapp" },
null);
ArrayList<String> myWhatsappContacts = new ArrayList<>();
String projection[] = { ContactsContract.CommonDataKinds.Phone.NUMBER };
if(c != null) {
if (c.getCount() > 0) {
while (c.moveToNext()) {
String whatsappContactId = c.getString(c.getColumnIndex(ContactsContract.RawContacts.Data._ID));
Cursor dataCursor = cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
projection,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
new String[]{whatsappContactId}, null);
// You can also read RawContacts.CONTACT_ID to read the
// …Run Code Online (Sandbox Code Playgroud) android contacts android-contentresolver android-contacts whatsapp