我正在尝试让用户选择联系人并检索他的电话号码。我在https://developer.android.com
中找到了以下代码//the onClick function for the user to pick his contact
public void pickContact(View view) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent, REQUEST_SELECT_PHONE_NUMBER);
}
}
//the function that should retrieve the phone number
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_SELECT_PHONE_NUMBER && resultCode == RESULT_OK) {
// Get the URI and query the content provider for the phone number
Uri contactUri = data.getData();
ContentResolver resolver = getContentResolver();
String[] projection = new String[]{ContactsContract.CommonDataKinds.Phone.NUMBER};
Cursor cursor = resolver.query(contactUri, projection, null, null, null);
// If the cursor returned is valid, get the phone number
if (cursor != null && cursor.moveToFirst()) {
int numberIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
String number = cursor.getString(numberIndex);
// Do something with the phone number
}
}
}
我不知道为什么但是当用户选择联系人时,应用程序会崩溃并出现以下错误:E / EGL_emulation:tid 5883:eglSurfaceAttrib(1165):错误0x3009(EGL_BAD_MATCH)。从调试来看,它似乎崩溃了这一行:
Cursor cursor = resolver.query(contactUri,
projection, null, null, null);
编辑:logcat消息:
03-07 11:16:53.239 5866-5883 / com.example.roy.wakeapp I / OpenGLRenderer:初始化的EGL,版本1.4 03-07 11:16:53.265 5866-5883 / com.example.roy.wakeapp E / EGL_emulation:tid 5883:eglSurfaceAttrib(1165):错误0x3009(EGL_BAD_MATCH) 03-07 11:16:53.265 5866-5883 / com.example.roy.wakeapp W / OpenGLRenderer:无法在表面0xad1ab480上设置EGL_SWAP_BEHAVIOR,错误= EGL_BAD_MATCH
我试着查一查,但找不到原因。 如果有人知道原因或可以提供不同的方式,我会很高兴:)
谢谢!
答案 0 :(得分:0)
尝试按以下方式实例化type TypeA = {|
type: "a",
value: number,
|};
type TypeB = {|
type: "b",
value: Array<number>,
|};
type SuperType =
| {|
...TypeA,
color: string,
|}
| TypeB;
function test(val: SuperType): void {
if (val.type === "b") {
// Flow should probably know that val.value is an array here
console.log(val.value.length);
}
}
Intent
和活动结果方法
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(intent, CONTACT_PICK);