示例代码中选用获取联系人电话号码为例,同学们举一反三,扩展其他,代码如下:
var REQUESTCODE = 1000;
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.Contacts.CONTENT_URI);
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 s_ret;
var givenName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
s_ret = givenName;
var contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
var pCursor = resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId,
null, null);
while (pCursor.moveToNext()) {
phoneNumber = pCursor.getString( pCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
s_ret += '\n' + phoneNumber;
}
alert(s_ret);
cursor.close();
pCursor.close();
}
};
main.startActivityForResult(intent, REQUESTCODE);
9***@qq.com
iOS的在这里:https://www.jianshu.com/p/b78b02d64472
2018-11-21 14:18