我想從我的聯繫人列表中我的應用程序中的聯繫人:選擇從聯繫人列表中的聯繫人崩潰的應用程序
public void selecionar_contato(View view) {
Intent intent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
startActivityForResult(intent, CONTACT_PICKER_RESULT);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
switch (requestCode) {
case CONTACT_PICKER_RESULT:
Uri dados = data.getData();
Cursor c = getContentResolver().query(dados, new String[]{
ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.CommonDataKinds.Phone.TYPE }, null, null, null);
if(c.moveToFirst()){
String num = c.getString(0);
int type = c.getInt(1);
mostarToast(type,num);
}
break;
}
} else {
// gracefully handle failure
Log.w("Erro", "Warning: ac");
}
}
private void mostarToast(int type, String num) {
Toast.makeText(this, type + ": " + num, Toast.LENGTH_LONG).show();
}
但是,當我選擇聯繫人,我的應用程序崩潰:
09-21 17:44:40.897: E/AndroidRuntime(17432): FATAL EXCEPTION: main
09-21 17:44:40.897: E/AndroidRuntime(17432): Process: com.example.pacixmobile, PID: 17432
09-21 17:44:40.897: E/AndroidRuntime(17432): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1001, result=-1, data=Intent { dat=content://com.android.contacts/contacts/lookup/298i107/602 flg=0x1 }} to activity {com.example.pacixmobile/com.example.pacixmobile.CadastroActivity}: java.lang.IllegalArgumentException: Invalid column data1
09-21 17:44:40.897: E/AndroidRuntime(17432): at android.app.ActivityThread.deliverResults(ActivityThread.java:3551)
我必須覆蓋onActivityResult方法嗎?我錯過了什麼?