android SIM聯繫人(轉)

一、啓動SIM聯繫人導入手機 INTENT

  1. // SIM import   
  2.                                         Intent importIntent = new  Intent(Intent.ACTION_VIEW);  
  3.                                         importIntent.setType("vnd.android.cursor.item/sim-contact" );  
  4.                                         importIntent.setClassName("com.android.phone" ,  
  5.                                                         "com.android.phone.SimContacts" );  
  6.                                         startActivity(importIntent);  

二、讀取SIM卡聯繫人

  1. Cursor cursor = getSIMContacts();  
  2.                                  while  (cursor !=  null  && cursor.moveToNext()) {  
  3.                                  String name = cursor.getString(cursor  
  4.                                                  .getColumnIndex("name" ));  
  5.                                  String number = cursor.getString(cursor  
  6.                                                  .getColumnIndex("number" ));         
  7.                                  }  
  8.         private  Cursor getSIMContacts() {  
  9.                 // Run query   
  10.                 Uri uri = Uri.parse("content://icc/adn" );// Contacts.People.CONTENT_URI;  
  11.                 // Uri uri = Uri.parse("content://sim/adn");   
  12.                 String[] projection = new  String[] {  "name" "phone"  };  
  13.                 String selection = null ;  
  14.                 String[] selectionArgs = null ;  
  15.                 String sortOrder = "name" // Contacts.People.NAME//   
  16.                                 // Contacts.PeopleColumns.DISPLAY_NAME   
  17.                                 + " COLLATE LOCALIZED ASC" ;  
  18.                 return  managedQuery(uri, projection, selection, selectionArgs,  
  19.                                 sortOrder);  
  20.         }  

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章