请教一下大牛!有关于android 通过电话号码查询通讯录的问题。

============问题描述============


 private void getContactPeople(String incomingNumber)

    {

    	myTextView1.setTextColor(Color.BLUE);

    	ContentResolver contentResolver = getContentResolver();

    	Cursor cursor = null;

    	

    	String[] projection = new String[]

    	{

    		ContactsContract.Contacts._ID,

    		ContactsContract.Contacts.DISPLAY_NAME,

    		ContactsContract.CommonDataKinds.Phone.NUMBER

    	};



    	cursor = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection, 

        ContactsContract.CommonDataKinds.Phone.NUMBER + "=?", new String[]

        { incomingNumber }, "");

    	if(cursor.getCount() == 0)

    	{

    		myTextView1.setText("unknown Number:" + incomingNumber);

    	}

    	else if (cursor.getCount() > 0)

    	{

    		cursor.moveToFirst();

    		String name = cursor.getString(1);

    		myTextView1.setText(name + ":" + incomingNumber);

    	}

    }

代码是为了根据电话号码,来查询通讯录里的联系人的名称。通讯录里有incomingNumber的号码的联系人,可是cursor.getCount()就是等于0,请教一下是什么原因,程序应该怎么改。

============解决方案1============


我用你的方法写了一个可运行程序,共享下代码
http://download.csdn.net/detail/qianqucaicaizi/4276224
posted @ 2014-10-24 09:27  android应用开发  阅读(361)  评论(0编辑  收藏  举报
我要啦免费统计