我正在尝试使用联系人选择器获取所选联系人的电子邮件地址。
但它没有用。
这是我的代码: -
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(resultCode == RESULT_OK)
{
Uri contactData = data.getData();
Log.e(TAG, contactData.toString());
String[] PROJECTION = new String[] {ContactsContract.CommonDataKinds.Email.DATA};
Cursor contactInfo = managedQuery(contactData, PROJECTION, null, null, null);
if(contactInfo.moveToFirst())
{
String name = contactInfo.getString(0);
Log.e(TAG, name);
}
else
{
Log.e(TAG, "No Data");
}
}
}
}
这是一个堆栈跟踪: -
10-31 23:47:29.912: ERROR/AndroidRuntime(1978): FATAL EXCEPTION: main
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1001, result=-1, data=Intent { dat=content://com.android.contacts/contacts/lookup/0r1-572D4F5547/1 flg=0x1 (has extras) }} to activity {com.varundroid.comm/com.varundroid.comm.InstantEmail}: java.lang.IllegalArgumentException: Invalid column data1
at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:2574)
at android.app.ActivityThread.access$2000(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:961)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: Invalid column data1
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:144)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)
at android.content.ContentProviderProxy.bulkQueryInternal(ContentProviderNative.java:330)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
at android.content.ContentResolver.query(ContentResolver.java:262)
at android.app.Activity.managedQuery(Activity.java:1550)
at com.varundroid.comm.InstantEmail.onActivityResult(InstantEmail.java:56)
at android.app.Activity.dispatchActivityResult(Activity.java:3908)
at android.app.ActivityThread.deliverResults(ActivityThread.java:2528)
... 11 more
如果我想获取一个名称然后它的工作,但如果我尝试获取一个电子邮件,它会抛出异常。
任何帮助都将受到高度赞赏。
感谢。
答案 0 :(得分:1)