How to read android sim contacts and phone contacts separately

前端 未结 2 658
一生所求
一生所求 2020-12-15 01:46

I want to read all sim contacts and phone contacts separately in Android. I searched for this and found lots of people having problem with this and I couldn\'t find any solu

相关标签:
2条回答
  • 2020-12-15 02:04

    for Phone contacts

    try
    {
        String[] PROJECTION=new String[] {Contacts._ID,
            Contacts.DISPLAY_NAME,
            Phone.NUMBER
        };
    
        Cursor c=managedQuery(Phone.CONTENT_URI,
            PROJECTION, null, null, null);
            if (c.moveToFirst()) {
                String ClsPhonename = null;
                String ClsphoneNo = null;
    
                do 
                {
                    ClsPhonename = c.getString(c.getColumnIndex(Contacts.DISPLAY_NAME));
                    ClsphoneNo = c.getString(c.getColumnIndex(Phone.NUMBER));
    
    
                    ClsphoneNo.replaceAll("\\D", "");
                    ClsPhonename=ClsPhonename.replaceAll("&", "");
                    ClsPhonename.replace("|","");
                    String ClsPhoneName=ClsPhonename.replace("|","");
    
                    }   
    
                } while(c.moveToNext());
            }
    

    for sim contacts

    String ClsSimPhonename = null; String ClsSimphoneNo = null;

        Uri simUri = Uri.parse("content://icc/adn"); 
        Cursor cursorSim = this.getContentResolver().query(simUri,null,null,null,null);
    
        while (cursorSim.moveToNext()) 
        {      
            ClsSimPhonename =cursorSim.getString(cursorSim.getColumnIndex("name"));
            ClsSimphoneNo = cursorSim.getString(cursorSim.getColumnIndex("number"));
            ClsSimphoneNo.replaceAll("\\D","");
            ClsSimphoneNo.replaceAll("&", "");
            ClsSimPhonename=ClsSimPhonename.replace("|","");
                System.out.println("SimContacts"+ClsSimPhonename);
                System.out.println("SimContactsNo"+ClsSimphoneNo);
                dts.createDatabse("MyCellFamily",getApplicationContext());
    
        }        
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    
    0 讨论(0)
  • 2020-12-15 02:18

    I found many phones use "com.android.contacts.sim" in RawContacts.ACCOUNT_TYPE for sim contacts. But I also found that HTC use "com.anddroid.contacts.sim" (misspelled for android). That is weird.

    0 讨论(0)
提交回复
热议问题