xml.java
主要就是垂直线性布局,里面放2个TextView和1个Button按钮
MainActivity.java
public class MainActivity extends AppCompatActivity {
private Cursor cursor;
private TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = findViewById(R.id.text);
}
public void btn(View view) {
try{
ContentResolver contentResolver = getContentResolver();
Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
cursor = contentResolver.query(uri, null, null, null,null);
text.setText("");
while (cursor.moveToNext()){
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String number = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
text.append("姓名:"+name+" ");
text.append("电话号码:"+number);
text.append("\n");
}
cursor.close();
}catch (Exception ignore){
Toast.makeText(getApplicationContext(),"",Toast.LENGTH_SHORT).show();
}
}
}
设计效果图
刚进入APP
原创文章 19获赞 55访问量 4712
关注
私信
展开阅读全文
作者:时光踏路已久