【问题标题】:Android contentprovider not returning Phone.NUMBERAndroid contentprovider 未返回 Phone.NUMBER
【发布时间】:2012-02-05 00:56:02
【问题描述】:

(更新)这适用于模拟器,但不适用于我的 HTC 传奇 :(

我的 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();
   }
 }

【问题讨论】:

  • 您设备的 API 级别是多少?
  • 尽量不要使用id。我的意思是尝试获取所有条目。也许问题是您使用了错误的 id
  • 您确定您没有使用另一个表的 id,例如 raw_contact 表而不是数据表吗?

标签: java android


【解决方案1】:

在清单中添加Read_contacts 权限。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-15
    • 1970-01-01
    • 1970-01-01
    • 2011-05-24
    • 1970-01-01
    • 1970-01-01
    • 2011-02-04
    • 2012-03-28
    相关资源
    最近更新 更多