【问题标题】:Android adding new contacts in simAndroid 在 SIM 卡中添加新联系人
【发布时间】:2012-04-27 05:36:00
【问题描述】:

当我们添加new contact并选择选项save to sim时,联系人是否也保存在RawContacts和Contacts表中。而且,当我们使用contact application 查看手机中的所有联系人时,它是否会显示来自 sim 的 sim 联系人或 sim 联系人是否保存在联系人表中,并且联系人应用程序会从那里显示 sim 联系人。

【问题讨论】:

    标签: android android-contacts


    【解决方案1】:
    try{
                // add a row to the RawContacts table
         ContentValues values = new ContentValues();
         values.put(RawContacts.ACCOUNT_TYPE, "com.anddroid.contacts.sim");
         values.put(RawContacts.ACCOUNT_NAME, "SIM");
         Uri rawContactUri = getContentResolver().insert(RawContacts.CONTENT_URI, values);
    
                // get the ID of the newly-added line
         long rawContactId = ContentUris.parseId(rawContactUri);
    
                // add a "name" line to the Data table, linking it to the new RawContact
                // with the CONTACT_ID column
         values.clear();
         values.put(Data.RAW_CONTACT_ID, rawContactId);
         values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
         values.put(StructuredName.DISPLAY_NAME, "Name");
         cr.insert(Data.CONTENT_URI, values);
                // this insert succeeds
    
                // add a "phone" line to the Data table, linking it to the new RawContact
                // with the CONTACT_ID column
         values.clear();
         values.put(Data.CONTACT_ID, rawContactId);
         values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
         values.put(Phone.NUMBER, "+12345678901");
         values.put(Phone.TYPE, Phone.TYPE_MOBILE);
         cr.insert(Data.CONTENT_URI, values);
                // this insert fails with a NullPointerException
    }
    catch(Exception e){
        String xx=e.toString();
        System.out.println(xx);
    }
    

    【讨论】:

      猜你喜欢
      • 2012-06-25
      • 2011-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-05
      相关资源
      最近更新 更多