打开studio在左侧列表中找到config.xml文件,双击打开,选择插件选项勾选cordova-plugin-contacts文件,并在权限选项中选择相关权限。最后保存文件。

联系人

summer框架中的联系可以使用cordova插件(cordova-plugin-contacts),主要功能包含:

1、查寻联系人

  1. navigator.contacts.find({
  2. 'filter':'xxx', //查询联系人的字段选项
  3. 'multiple':true, //是否返回多个查询结果
  4. 'hasPhoneNumber':true, //是否只返回联系电话号码
  5. 'desiredFields':[navigator.contacts.fieldType.name], //返回联系人的对象包含的字段的值(可以选择不同的返回值)
  6. 'fieldType':[navigator.contacts.fieldType.name]}, //按照该字段选项查询联系人(可以多选)
  7. function (contacts) {
  8. alert(contacts); //成功返回的数据
  9. alert(navigator.contacts.fieldType); //所有字段选项
  10. },
  11. function (contactError) {
  12. alert('onError!'); //失败返回的错误信息
  13. }
  14. )

2、保存联系人

  1. function onSuccess(contact) {
  2. alert("Save Success");
  3. };
  4. function onError(contactError) {
  5. alert("Error = " + contactError.code);
  6. };
  7. // create a new contact object
  8. var contact = navigator.contacts.create();
  9. contact.displayName = "海滨2";
  10. contact.nickname = "qq2"; // specify both to support all devices
  11. // save to device
  12. contact.save(onSuccess,onError);

用例github下载地

更多参见

文档更新时间: 2018-01-15 13:50