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