package com.xyz.tryit;
import android.app.Activity;
import android.database.Cursor;
//import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
//import android.provider.Contacts.People;
import android.provider.ContactsContract.PhoneLookup;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class myActivity extends Activity {
/** Called when the activity is first created. */
private Button start;
private malay Malay;
class malay implements OnClickListener{
@Override
public void onClick(View v) {
System.out.print("hiiiiiiii");
// TODO Auto-generated method stub
/*String[] projection=new String[]{
People._ID,People._COUNT,People.NAME,People.NUMBER
};
Uri contacts=People.CONTENT_URI;
Cursor managedCursor=managedQuery(ContactsContract.Contacts.CONTENT_URI,projection,null,null,People.NAME+"ASC");
*/
readData();
}
public void readData(){
Cursor people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while(people.moveToNext()) {
int nameFieldColumnIndex = people.getColumnIndex(PhoneLookup.DISPLAY_NAME);
String contact = people.getString(nameFieldColumnIndex);
int numberFieldColumnIndex = people.getColumnIndex(PhoneLookup.NUMBER);
String number = people.getString(numberFieldColumnIndex);
System.out.println("NAME====="+contact+" NUMBER======="+number);
}
people.close();
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Malay=new malay();
this.start=(Button)this.findViewById(R.id.Button01);
System.out.print("hellllllllloooooooooo");
start.setOnClickListener(Malay);
}
}
答案 0 :(得分:1)
您是否申请了READ_CONTACTS权限 在AndroidManifest.xml中?
<uses-permission android:name="android.permission.READ_CONTACTS"/>