android获取联系人信息错误 本帖最后由 zclmoon 于 2010-12-28 20:59:38 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 首先,你在android自带的联系人新建联系人了没,如果没有,那么你这个cursor就指空了。 你这个类是不是继承了Activity类啊。如果是的话,还要在androidManifest.xml中注册哦!还有就是把你出错的信息也写出来撒! Uri uri = Uri.parse("content://icc/adn");String[] projection = {"_id", "name", "number"};Cursor cursor = managedQuery(uri, projection, null, null, "name");if(cursor!=null){ while(cursor.moveToNext()){ String name = cursor.getString(cursor.getColumnIndex("name")); String phone = cursor.getString(cursor.getColumnIndex("number")); }}/*在文件AndroidManifest.xml中添加权限<uses-permission android:name="android.permission.READ_PHONE_STATE"/>Android系统内部通过Contentprovider对外共享Sim卡存放的联系人等信息,你可以通过操作Contentprovider来实现Sim卡信息的添删改查操作*/ 我新建了你Hello空工程,在Hello.java里面就写这两句代码: ContentResolver cr = getContentResolver(); Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); 运行时候就出现这样的问题哈我也在AndroidManifest.xml中加了:<uses-permission android:name="android.permession.READ_CONTACTS"/> // 取得ContentResolver对象 ContentResolver cr = getContentResolver(); // 取得通讯录的光标 String orderBy = PhoneLookup.DISPLAY_NAME + " COLLATE LOCALIZED ASC"; Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, orderBy);取的没问题,是不是权限没有加在</application>的外面。 加个 projection 啊, 不然你这个query有啥意义啊? 我加在外面啊。。<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.zcl.android.Test" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".Test" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="8" /> <uses-permission android:name="android.permession.READ_CONTACTS"/> </manifest> 从网络读取图片 图片无法显示 Android默认的尺寸单位以及和像素单位的转换 android如何访问sqlserver数据库来实现客户端的登录注册呢。 android生命周期问题 如何去掉几个ImageButton之间的空隙 神奇的webview,有人遇到过这种情况吗 不知道才是最难的,求大神帮忙 JNI能否提升处理BITMAP速度?????? 摄像头遮挡提示的原理是什么 安全软件禁止第三方锁屏软件侵犯锁屏界面,该如何做 是否有公认的异步http请求的写法? Android编程先登录网站然后访问本网站不同网页
String[] projection = {"_id", "name", "number"};
Cursor cursor = managedQuery(uri, projection, null, null, "name");
if(cursor!=null){
while(cursor.moveToNext()){
String name = cursor.getString(cursor.getColumnIndex("name"));
String phone = cursor.getString(cursor.getColumnIndex("number"));
}
}/*在文件AndroidManifest.xml中添加权限
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>Android系统内部通过Contentprovider对外共享Sim卡存放的联系人等信息,你可以通过操作Contentprovider来实现Sim卡信息的添删改查操作*/
运行时候就出现这样的问题哈我也在AndroidManifest.xml中加了:
<uses-permission android:name="android.permession.READ_CONTACTS"/>
ContentResolver cr = getContentResolver();
// 取得通讯录的光标
String orderBy = PhoneLookup.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, orderBy);取的没问题,是不是权限没有加在</application>的外面。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zcl.android.Test"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Test"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> </application>
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permession.READ_CONTACTS"/>
</manifest>