简体   繁体   中英

Android contentprovider not returning Phone.NUMBER

(UPDATE) This works on emulator but not on my HTC legend :(

I have the following method in my ListActivity and it is not returning any values in the Cursor (getCount=0)

I can't quite work out why. It doesn't matter which contact I click on in my List.

protected void onListItemClick(ListView l, View v, int position, long id) {
   // TODO Auto-generated method stub
   super.onListItemClick(l, v, position, id);
   Log.d(TAG,"onListItemClick");

   //get Telephone number for entry and display in Toast
   Uri phoneUri = ContentUris.withAppendedId(Phone.CONTENT_URI, id);
   Log.d(TAG,String.valueOf(phoneUri));
   String[] projection = new String[]{Phone.NUMBER};


   //Get Cursor
   Cursor phoneCursor = managedQuery(phoneUri, projection, null, null, null);

   while(phoneCursor.moveToNext()){
       String dspNumber;
       String number = phoneCursor.getString(phoneCursor.getColumnIndexOrThrow(Phone.NUMBER));
       if(number==""){
           dspNumber = "No number found";
       }else{
           dspNumber = number;
       }

       Toast.makeText(this,dspNumber, 3000).show();
   }
 }

在清单中添加Read_contacts权限。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM