android 酷派 选择联系人报错

遇到一个bug,酷派手机在执行以下代码时会报错

Intent i = new Intent(Intent.ACTION_PICK);
                i.setType("vnd.android.cursor.dir/phone");
                startActivityForResult(i, SELECTNUMBER);
protected void onActivityResult(int requestCode, int resultCode, Intent dataIntent) {    super.onActivityResult(requestCode, resultCode, dataIntent);    if (requestCode == SELECTNUMBER && resultCode == RESULT_OK) {        if (dataIntent == null) {            return;        }    Uri uri = dataIntent.getData();    Cursor cursor = getContentResolver().query(uri, null, null, null, null);

  if (cursor.moveToFirst()) {
       name.setText(cursor.getString(cursor.getColumnIndexOrThrow(Contacts.Phones.NAME)) + "");      phone.setText(cursor.getString(cursor.getColumnIndexOrThrow(Contacts.Phones.NUMBER)) + "");
      if (Build.VERSION.SDK_INT < 14) {                cursor.close();            }
  }
}

 应该是因为没有实现返回带电话的联系人信息导致的。注释掉 i.setType("vnd.android.cursor.dir/phone"); 即可正常运行,但是在

onActivityResult无法通过游标获取到联系人姓名和电话。

网上查了后改为先读取联系人id,然后再去查找电话号码,这么一改代码臃肿了很多,不过为了兼容酷派也没办法.代码如下:
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
                if (getPackageManager().resolveActivity(intent, 0) != null) {
                    startActivityForResult(intent, SELECTNUMBER);
                } else {
                    showMsg("您的手机不支持选择通讯录联系人");
                }
protected void onActivityResult(int requestCode, int resultCode, Intent dataIntent) {    super.onActivityResult(requestCode, resultCode, dataIntent);    if (requestCode == SELECTNUMBER && resultCode == RESULT_OK) {        if (dataIntent == null) {            return;        }        Uri contactData = dataIntent.getData();        Cursor cursor = managedQuery(contactData, null, null, null, null);        String id = "";        if (cursor.moveToFirst()) {            name.setText(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)) + "");//name为TextView            String haanumber = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));            id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));            if (haanumber.equalsIgnoreCase("1")) {                Cursor phones =getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,                                ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + id, null, null);                while (phones.moveToNext()) {                    phone.setText(phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));//phone为TextView
                }                if (Build.VERSION.SDK_INT < 14) {                    phones.close();                }            }            if (Build.VERSION.SDK_INT < 14) {                cursor.close();            }        }    }}

  

时间: 2024-11-01 14:27:03

android 酷派 选择联系人报错的相关文章

android studio :com.android.support:appcompat-v7:21.+ 报错

android studio :com.android.support:appcompat-v7:21.+ 报错: 在project——>app——>build.gradle修改: apply plugin: 'com.android.application' android { compileSdkVersion 22 buildToolsVersion "22.0.1" defaultConfig { applicationId "com.example.ri

Android 线程更新UI报错 : Can&#39;t create handler inside thread that has not called Looper.prepare()

MainActivity中有一个按钮,绑定了save方法 public void save(View view) { String title = titleText.getText().toString(); String timelength = lengthText.getText().toString(); ExecutorService exec = Executors.newCachedThreadPool(); exec.execute(new NewsService(getApp

android studio - 导入工程报错[Plugin with id &#39;com.android.application&#39; not found]

出错现象: 大概意思是找不到:com.android.application 插件,以上现象对于初学者来说会经常碰到,下面分析下产生的原因. 原因分析 首先来看看导入后的工程结构: 对于此工程结构,是否有个疑问? 这是未正常同步完成的结构,Gradle Scripts下面似乎少了个 build.gradle ,上图红框部分描述清楚了是 Module: GraphicsDemo ,表示该 build.gradle 是Module的,而不是Project的.来看看一个正常的 Project+Modu

Mac OSX Android 开发环境 模拟器报错

直接下载ADT mac版 模拟器报错处理 1. 显示隐藏文件命令 显示:defaults write com.apple.finder AppleShowAllFiles -bool true隐藏:defaults write com.apple.finder AppleShowAllFiles -bool false 2. 修改 /.android/avd/你的模拟器名字/emulator-user.ini window.x = 0 原因没有深究,可能和双屏有关? Mac OSX Androi

android studio创建模拟器报错解决 emulator: ERROR: This AVD&#39;s configuration is missing a kernel file!!

android studio创建模拟器报错 emulator: ERROR: This AVD's configuration is missing a kernel file!! 的解决办法 原因有二:1 没有,解决办法通过sdk mangager 下载 2 找不到,解决办法看系统环境变量path(此种情况多数发生在android Studio和EclipseADT同时存在的情况下) 原因是在刚刚安装完毕的androidstudio的sdk目录下没有system-image目录,也许有但没有相

Android Studio集成SVN报错:can&#39;t use subversion command line client : svn

Android Studio集成SVN插件,check out出代码后,每次开启都会在右上角出现如下错误: Can't use Subversion command line client: svn Probably the path to Subversion executable is wrong. Fix it. Errors found while svn working copies detection. Fix it. 下面直接上解决方案吧: 1.安装客户端http://ncu.dl

Android Studo 使用 JNI报错:java.lang.UnsatisfiedLinkError: Couldn&#39;t load XXX from loader dalvik.system.PathClassLoader

今天在使用Android Studio的时候突然发现代码没错,so包也引入了,各个版本都引入了,但是就是一直报错: java.lang.UnsatisfiedLinkError: Couldn't load serphone from loader dalvik.system.PathClassLoader 11-30 11:13:18.766 29255-29255/com.personal.tai.ronglianim E/AndroidRuntime: at java.lang.Runti

Android读取选择联系人的模版代码实现

1.创建SelectContactActivity类,在AndroidManifest.xml添加类 import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.app.Activity; import android.content.ContentResolver; import android.content.Intent;

cocos2d-x android 添加新场景报错: undefined reference to `vtable for XXX&#39;

转载自 居家懒人 http://www.cnblogs.com/JD85/archive/2012/09/17/2688128.html 加入写了新场景SecondScene,结果在cpp文件里类名地方报错说undefined reference to `vtable for SecondScene', 很简单,貌似是每个新场景都要先注册一下,找到jni-->Classes目录下的Android.mk文件,在 LOCAL_SRC_FILES := AppDelegate.cpp HelloWor