求助各位哥哥姐姐们,有些手机(主要是三星samsung-SM-J415G,摩托罗拉motorola-moto e(6) plus)等,无法调用通讯录(打开系统的通讯录页面),是代码哪里写错了吗? 代码如下
var REQUESTCODE = 1000
let that = this
let main = plus.android.runtimeMainActivity();
var Intent = plus.android.importClass('android.content.Intent');
var ContactsContract = plus.android.importClass('android.provider.ContactsContract');
var intent = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI );
intent.setPackage("com.android.contacts");
main.onActivityResult = function(requestCode, resultCode, data) {
if (REQUESTCODE == requestCode) {
var phoneNumber = null;
var resultString = "";
var context = main;
plus.android.importClass(data);
var contactData = data.getData();
var resolver = context.getContentResolver();
plus.android.importClass(resolver);
var cursor = resolver.query(contactData, null, null, null, null);
plus.android.importClass(cursor);
cursor.moveToFirst();
var givenName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
let concactStr = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
//返回选择的号码
uni.$emit('returnPhone',givenName+':'+concactStr)
cursor.close();
pCursor.close();
}else{
console.log('error')
}
};
main.startActivityForResult(intent, REQUESTCODE)
1 个回复
2***@qq.com (作者) - 小曾
var intent = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI );
用ContactsContract.CommonDataKinds.Phone.CONTENT_URI 是想要在打开的通讯录里显示用户名和手机号码