2012-01-07 33 views
6

(更新)這工作在模擬器卻沒有關於我的HTC Legend :(的Android的ContentProvider沒有返回Phone.NUMBER

我在ListActivity下面的方法,它是不是在返回遊標的任何值(getCount將= 0)

我不是很明白爲什麼。不要緊,我在列表中點擊哪個接觸。

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(); 
    } 
} 
+0

什麼是API你的設備級別? – Gnufabio 2012-01-07 21:49:21

+1

儘量不要使用該ID。我的意思是嘗試獲取所有條目。也許問題在於你使用了錯誤的編號 – kingston 2012-01-07 23:33:01

+1

你確定你沒有使用另一個表的id,例如raw_contact表而不是數據表嗎? – kingston 2012-01-07 23:48:54

回答

0

添加Read_contacts許可清單中。