相关疑难解决方法(0)

如何从Android中的电话簿和SIM卡获取所有联系人?

我正在努力从我的应用程序中获取电话簿和SIM卡的所有联系人.我想将所有联系人存储在我的应用程序SQLite DB中.我正在使用的代码在正常条件下正常工作.在以下条件下遇到问题:

  1. 没有姓名的联系人,这只是号码.
  2. 来自SIM卡的联系人.

我的代码不向我提供这两种类型的联系人.我使用以下代码:

public void getDefaultContactsToDB(){
        CallBackDatabase callbackDB = new CallBackDatabase(RequestCallBack.this);
        callbackDB.open();

        //clean the database before entering new values.
        callbackDB.deleteTable(CallBackDatabase.DATABASE_TABLE);

        ContentResolver cr = getContentResolver();
        Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
        if (cur.getCount() > 0) {
            while (cur.moveToNext()) {
                String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
                Cursor cur1 = cr.query( 
                        ContactsContract.CommonDataKinds.Email.CONTENT_URI, null,
                        ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?", 
                        new String[]{id}, null); 
                while (cur1.moveToNext()) { 
                    //to get the contact names
                    ArrayList<String> numbers= new ArrayList<String>();
                    String contactNoumber="";
                    String name=cur1.getString(cur1.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
                    if(name!=null){
                        Log.e("Name :", name);
                        if(name.equalsIgnoreCase("011999999999999999")){ …
Run Code Online (Sandbox Code Playgroud)

android android-contacts

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

android-contacts ×1