我认为的值int index=data.getIntExtra("recordindex", 0)
应该是 60,但我得到的值是 0,为什么?
我犯了什么错误?谢谢!
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.sms_tel_number);
Button btnadd = (Button) findViewById(R.id.btnadd);
btnadd.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
i.putExtra("recordindex", 60);
startActivityForResult(i, 50);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case 50:
if (resultCode == RESULT_OK) {
if (data == null) {
return;
}
//------------------------------------------------
ContentResolver reContentResolverol = getContentResolver();
Uri contactData = data.getData();
int index=data.getIntExtra("recordindex", 0); //The value should be 60, but it's 0, why
Cursor cursor = managedQuery(contactData, null, null, null, null);
if (cursor.moveToFirst()) {
String username = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
Cursor phone = reContentResolverol.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID
+ " = " + contactId, null, null);
if (phone.moveToFirst()) {
String usernumber = phone.getString(phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Toast.makeText(getApplicationContext(), index + " B " + usernumber, Toast.LENGTH_SHORT).show();
}
}
//------------------------------------------------
}
break;
default:
break;
}
}
}