在 JS 中获取联系人列表
get contact list in JS
我想从 Android 获取联系人列表(如果用户在 android 中打开网站)。我正在搜索它。我在Whosebug中发现了两个类似的问题。
Obtain Contacts Permission before Navigating (Cordova)
-
这是我试过的。
function onSuccess(contacts) {
alert('Found ' + contacts.length + ' contacts.');
};
function onError(contactError) {
alert('onError!');
};
// find all contacts with 'Bob' in any name field
var options = new ContactFindOptions();
options.filter = "Bob";
options.multiple = true;
options.desiredFields = [navigator.contacts.fieldType.id];
options.hasPhoneNumber = true;
var fields = [navigator.contacts.fieldType.displayName, navigator.contacts.fieldType.name];
navigator.contacts.find(fields, onSuccess, onError, options);
我在 android 中没有收到任何错误或警告消息。当我在 PC 上访问网页时出现错误
Uncaught ReferenceError: ContactFindOptions is not defined
at contacts.php:17
我想我有错误原因,PC 中没有联系人功能。
我是 JS 的初学者。我想Cordova must be installed in PC,我也不确定这个信息。如果必须,我该如何安装 Cordova?我正在使用基于 Debian Linux 的发行版。所以,我尝试了
sudo apt-get install cordova
但是,
E: Unable to locate package cordova
您是在使用 Cordova 构建移动应用程序,还是只是 运行在 Android 上的网站上使用您的代码?
如果它只是一个网站:您根本无法做您想做的事,因为浏览器不提供联系人列表的界面。
不像 Cordova 应用程序,它可以访问系统 APIs,其中联系人列表 API,JavaScript 在移动浏览器中执行的代码,无法访问这样的 API秒。浏览器JSAPI根本就没有办法
JavaScript 代码 运行 在 Cordova/Capacitor 移动应用程序中,但是 Cordova APIs 可以桥接移动设备的原生 API 到 JavaScript .
我想从 Android 获取联系人列表(如果用户在 android 中打开网站)。我正在搜索它。我在Whosebug中发现了两个类似的问题。
Obtain Contacts Permission before Navigating (Cordova)
这是我试过的。
function onSuccess(contacts) {
alert('Found ' + contacts.length + ' contacts.');
};
function onError(contactError) {
alert('onError!');
};
// find all contacts with 'Bob' in any name field
var options = new ContactFindOptions();
options.filter = "Bob";
options.multiple = true;
options.desiredFields = [navigator.contacts.fieldType.id];
options.hasPhoneNumber = true;
var fields = [navigator.contacts.fieldType.displayName, navigator.contacts.fieldType.name];
navigator.contacts.find(fields, onSuccess, onError, options);
我在 android 中没有收到任何错误或警告消息。当我在 PC 上访问网页时出现错误
Uncaught ReferenceError: ContactFindOptions is not defined at contacts.php:17
我想我有错误原因,PC 中没有联系人功能。 我是 JS 的初学者。我想Cordova must be installed in PC,我也不确定这个信息。如果必须,我该如何安装 Cordova?我正在使用基于 Debian Linux 的发行版。所以,我尝试了
sudo apt-get install cordova
但是,
E: Unable to locate package cordova
您是在使用 Cordova 构建移动应用程序,还是只是 运行在 Android 上的网站上使用您的代码?
如果它只是一个网站:您根本无法做您想做的事,因为浏览器不提供联系人列表的界面。
不像 Cordova 应用程序,它可以访问系统 APIs,其中联系人列表 API,JavaScript 在移动浏览器中执行的代码,无法访问这样的 API秒。浏览器JSAPI根本就没有办法
JavaScript 代码 运行 在 Cordova/Capacitor 移动应用程序中,但是 Cordova APIs 可以桥接移动设备的原生 API 到 JavaScript .