你的他(她)通讯记录在手天下我有(10)

阅读更多

               那么这一节就迎来激动人心的通讯录在手天下我有的章节蠢话

  • CallLog.Calls._ID
  • CallLog.Calls.CACHED_NAME
  • CallLog.Calls.NUMBER

想要知道你亲爱的他(她)是被动接到还是主动拨出么,这里涉及到,呼叫类型

CallLog.Calls.TYPE

  • 拨出 outgoing
  • 拨入 incoming
  • 未接 missed

本实例只实现读取id,人名,电话号码,有心人可以自加功能

主布局函数:

 


	
	

 

listview模板布局函数定义:



	
		
		
		
	

 

主函数Activity

public class MainActivity extends Activity {

	private ListView calllist=null;
	private Cursor result=null;//找联系人
	private List> allcalls=null;
	private SimpleAdapter simple=null;
	
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		this.calllist=(ListView)super.findViewById(R.id.callList);
		//操作的uri,简单来说就是找到人家的门牌号。
		this.result=super.getContentResolver().query(CallLog.Calls.CONTENT_URI,null, null, null, null);
		this.startManagingCursor(result);//cursor交给系统管理
		allcalls=new ArrayList>();
		//找到数据一个个往Map存
		for(result.moveToFirst();!result.isAfterLast();result.moveToNext()){
			Map map=new HashMap();
			map.put("id", result.getInt(result.getColumnIndex(CallLog.Calls._ID)));
			String name=result.getString(result.getColumnIndex(CallLog.Calls.CACHED_NAME));
			//设置未知电话,也就是手机联系人里所没有的
			if(name==null||"".equals(name)){
				name="未知";
			}
			map.put("name", name);
			map.put("number", result.getString(result.getColumnIndex(CallLog.Calls.NUMBER)));
			this.allcalls.add(map);
		}
		this.simple=new SimpleAdapter(this,this.allcalls,
				R.layout.call,//模板
				new String[]{"id","name","number"},//匹配Map集合的key
				new int[]{R.id._id,R.id.name,R.id.number}//设置显示数据
				);
		this.calllist.setAdapter(simple);
		
		
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}

 注意配置权限


	

 

效果如下:


你的他(她)通讯记录在手天下我有(10)_第1张图片
 

  • 你的他(她)通讯记录在手天下我有(10)_第2张图片
  • 大小: 68.9 KB
  • 查看图片附件

你可能感兴趣的:(安卓;通讯录;联系人)