button 跳转到电话薄,点击获取电话号码到textview

button.setonclicklister(......){

........

                        Intent intent=new Intent();

String action=Intent.ACTION_GET_CONTENT;

String uri="vnd.android.cursor.item/phone";

intent.setAction(action);

intent.setType(uri);

startActivityForResult(intent, 0);

}

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

// TODO Auto-generated method stub

super.onActivityResult(requestCode, resultCode, data);

if(requestCode==0&&resultCode==RESULT_OK){

//查询返回的结果

Uri uri=data.getData();

//定义要查询的列明

String[] projection={"number"};

System.out.println("uri="+uri);

//游标是指向查询结果集的指针

Cursor cursor=managedQuery(uri, projection, null, null, null);

//遍历第一条数据

cursor.moveToFirst();

//获取当前右边指针指向的索引。来查找当前的列。

String number=cursor.getString(cursor.getColumnIndex("number"));

text.setText(number);

}

}

 

你可能感兴趣的:(获取,button,号码,电话簿)