现在的位置: 首页 > 综合 > 正文

新公司的第一天,纪念一下,上传个导入sim联系人的方法

2013年06月13日 ⁄ 综合 ⁄ 共 1269字 ⁄ 字号 评论关闭
1.启动SIM联系人导入手机INTENT
                                        // SIM import
                                        Intent importIntent = new Intent(Intent.ACTION_VIEW);
                                        importIntent.setType("vnd.android.cursor.item/sim-contact");
                                        importIntent.setClassName("com.android.phone",
                                                        "com.android.phone.SimContacts");
                                        startActivity(importIntent);

2.读取SIM卡联系人
                                 Cursor cursor = getSIMContacts();
                                 while (cursor != null && cursor.moveToNext()) {
                                 String name = cursor.getString(cursor
                                                 .getColumnIndex("name"));
                                 String number = cursor.getString(cursor
                                                 .getColumnIndex("number"));        
                                 }

        private Cursor getSIMContacts() {
                // Run query
                Uri uri = Uri.parse("content://icc/adn");// Contacts.People.CONTENT_URI;
                // Uri uri = Uri.parse("content://sim/adn");
                String[] projection = new String[] { "name", "phone" };
                String selection = null;
                String[] selectionArgs = null;
                String sortOrder = "name"// Contacts.People.NAME//
                                // Contacts.PeopleColumns.DISPLAY_NAME
                                + " COLLATE LOCALIZED ASC";

                return managedQuery(uri, projection, selection, selectionArgs,
                                sortOrder);

        }



转来的

抱歉!评论已关闭.