ContactsContract.Contacts与ContactsContract.CommonDataKinds.Phone的区别
生活随笔
收集整理的這篇文章主要介紹了
ContactsContract.Contacts与ContactsContract.CommonDataKinds.Phone的区别
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
ContactsContract.Contacts:
Constants for the contacts table, which contains a record per aggregate of raw contacts representing the same person ? 常量的聯系人表,其中包含一個記錄每個聯系人表示同一個人的集合。 ContactsContract.CommonDataKinds: Container for definitions of common data types stored in the ContactsContract.Data table.? 容器數據類型定義的常見存儲在ContactsContract.Data表。 ContactsContract.CommonDataKinds.Phone: A data kind representing a telephone number. 一個數據類型代表一個電話號碼。 ContactsContract.CommonDataKinds.Phone.CONTENT_URI The content:// style URI for all data records of the CONTENT_ITEM_TYPE MIME type, combined with the associated raw contact and aggregate contact data. 內容:/ /風格URI對于所有數據記錄的內容項類型的MIME類型,結合相關的原始聯系人和集合聯系人數據。 ContactsContract.CommonDataKinds.Phone.NUMBER The phone number as the user entered it. 電話號碼。 以上內容是SDK上的內容,翻譯的不完全。但是都可以取得聯系人號碼,姓名等等。 import android.provider.Contacts;在Contacts上劃了橫線,所以應該是sdk已經取消的用法。 所以以下取聯系人資料的用法是有問題的。 String[] projection = new String[]{ Contacts.People._ID, Contacts.People.NAME, Contacts.People.NUMBER }; cursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection,? Contacts.People.NUMBER + "=" +incomingNumber,? null,? null); import android.provider.ContactsContract;是存在的,所以應該用ContacContract來取資料。 String[] projection = new String[]{ ContactsContract.Contacts._ID, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,//可以換為ContactsContract.Contacts.DISPLAY_NAME ContactsContract.CommonDataKinds.Phone.NUMBER//取電話號碼是唯一的。 }; cursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection,? ContactsContract.CommonDataKinds.Phone.NUMBER + "=" +incomingNumber,? null,? null); if(cursor.getCount()==0){ mTextView.setText("unknown number"); }else if(cursor.getCount()>0){ cursor.moveToFirst(); //在projection這個數組里名字是放在第1個位置 // String name = cursor.getString(1); String name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME)); mTextView.setText(name+":"+incomingNumber); } 別忘了權限。<uses-permission android:name="android.permission.READ_CONTACTS"/>? 涉及的代碼為:EX06_06.本文出自 “千尋” 博客,請務必保留此出處http://5200415.blog.51cto.com/3851969/971423
總結
以上是生活随笔為你收集整理的ContactsContract.Contacts与ContactsContract.CommonDataKinds.Phone的区别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 3 分钟搞定 Android Push
- 下一篇: Back 键与Home键