如何阅读Android的SIM卡联系人和手机联系人分开联系人、手机、Android、SIM

由网友(情场孤独王.)分享简介:我想单独读取所有SIM卡联系人和手机通讯录中的Andr​​oid。我搜索了这一点,并发现了大量与此有问题的人,我无法找到任何解决办法呢。我喜欢一些答案这里,但它不为我工作。当我测试这一点,给我的谷歌联系人:I want to read all sim contacts and phone contacts sepa...

我想单独读取所有SIM卡联系人和手机通讯录中的Andr​​oid。我搜索了这一点,并发现了大量与此有问题的人,我无法找到任何解决办法呢。我喜欢一些答案这里,但它不为我工作。 当我测试这一点,给我的谷歌联系人:

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 solution yet. I fond some answer here, but it doesn't work for me. When I test this it give me google contacts:

RawContacts.ACCOUNT_TYPE + " = 'com.google' "

但是当我测试这一点,不给我SIM卡联系人:

But when I test this it does not give me sim contacts:

RawContacts.ACCOUNT_TYPE + " = 'com.android.contacts.sim' "

后来我发现RawContacts是通过同步适配器此处。这可能是问题。因此,谁能告诉我相处的方式

Then I found RawContacts are contacts that created by sync adapter in here. That may be the problem. So can anyone tell me the way of getting

所有simcontacts 在所有手机中的联系人

感谢。

推荐答案

的手机通讯录

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());
        }

的SIM卡联系人

字符串ClsSimPhonename = NULL; 字符串ClsSimphoneNo = NULL;

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();
}
阅读全文

相关推荐

最新文章