如何删除android中最近调用列表中的特定联系人?

问题描述:

我创建了一个具有唯一键和布尔值的哈希映射。在密钥中,我得到了callog.calls的唯一ID。我想要的是,具有相应真值的那些键将从手机中的最近通话列表中删除。我需要知道如何从calllog.calls查询和删除选定的行。我想我自己,但代码是不工作如何删除android中最近调用列表中的特定联系人?

public void onclickhandler(View nn){ 
    boolean state=false; 
    rl=(RelativeLayout) nn.getParent(); 
    TextView tv=(TextView)rl.getChildAt(1); 
    cb=(CheckBox)rl.getChildAt(2); 
    if(cb.isChecked()){ 
     state=true; 
    } 

    String s=tv.getText().toString(); 
    hmp.put(s, state); 

    Log.i("value", tv.getText().toString()); 
    System.out.println(state); 
} //........... 
     //I want to delete the contacts on button click.here 
     //is the code for the listener.. 

done.setOnClickListener(new OnClickListener(){ 
    public void onClick(View v) { 
     // TODO Auto-generated method stub 

     ContentResolver cr = getContentResolver(); 
     Cursor cur = cr.query(CallLog.Calls.CONTENT_URI, 
           null, null, null, null); 
     Set keys = hmp.keySet(); 
     Iterator it=keys.iterator(); 

     while (it.hasNext()) { 
      String keyvalue=(String) it.next(); 

      if(hmp.get(keyvalue).booleanValue()==true){ 
       try{ 
        cur.moveToPosition(Integer.parseInt(keyvalue)); 
        String lookupKey = cur.getString(cur.getColumnIndex(
           CallLog.Calls.CACHED_NAME)); 

        Uri uri = Uri.withAppendedPath(
           CallLog.Calls.CONTENT_URI, lookupKey); 

        System.out.println("The uri is " + uri.toString()); 
        cr.delete(uri, null, null); 
       } 
       catch(Exception e) 
       { 
        System.out.println(e.getStackTrace()); 
       } 
      }//if  
     }//while 

    }//on click 
}); 
+0

你是否将这些值存储在数据库中,为什么我问的是bcoz你说过你会查询它们? – 2011-11-18 14:05:08

+0

不,我还没有创建自己的数据库。只是想从android.provider.contacts数据库中删除它们。 –

+0

你可以看到编辑后的版本,它对我实际上试图做的更清晰 –

for(Map.Entry<String, String> me:nameofHashMap.entrySet()) 

for(Entry<String, String> me:nameofHashMap.keySet()) 

使用这一说法得到你想要的值,并完成你的代码:)

me.getKey();将会为你提供你需要的所有价值。 “me”是你正在创建的对象的名称,给它任何你想要的名字并且调用这个对象。

+0

如何使用这个以及在哪里放。我认为问题仍然是一样的。我应该从数据库中查询一行。我想问题是在这里cr.delete(uri,where,null)...我一直无法弄清楚在哪里放置什么argument.let说我有一个唯一的ID,即一些number.how我可以删除一个完成对某些数字的行。感谢您的答复任何方式.. –

+0

编辑答案,检查它。 – 2011-11-22 07:15:24

+0

我正在得到我需要的值。问题是如何删除整个行对应的值。或什么要放在cr.delete(uri,where,null)的字段中......我不知道这种方法工作中。 –