【发布时间】:2014-07-20 11:17:39
【问题描述】:
尝试使用 Phonegap / Cordova 3.5.0-0.2.4 列出 Android 手机中的联系人,将“联系人”插件安装到应用程序文件夹中。
运行下面的步骤序列后,我们会得到一个默认的cordova索引页面显示在 带有消息“正在连接设备”
的设备它不显示存储在手机上的联系人。
请帮助我们。提前致谢。
Step1
$ cordova create conto com.example.conto
Step2
$ cordova platform add android
Step3
$ cordova plugin add org.apache.cordova.contacts
Step4
$ cordova plugin list (enter)
org.apache.cordova.contacts 0.2.11 "Contacts"
Step5
Added the following in "app/www/js/index.js"
function read_contacts(){
var options = new ContactFindOptions();
options.filter="";
options.filter="";
options.multiple=true;
var fields = ["*"]; //"*" will return all contact fields
navigator.contacts.find(fields, onSuccess, onError, options);
}
// display the address information for all contacts
function onSuccess(contacts) {
//console.log(JSON.stringify(contacts))
var li = '';
$.each(contacts, function(key, value) {
if(value.name){
$.each(value.name, function(key, value) {
if(key == 'formatted'){
name = value;
}
});
}
if(value.phoneNumbers){
$.each(value.phoneNumbers, function(key, value) {
phone = value.value;
});
}
li += '<li style="text-decoration:none;">'+name+' '+phone+'</li>';
});
$("#contact").html(li);
}
function onError(contactError) {
alert('onError!');
}
Step6:
Added the following in "app/www/index.html"
<ol id="contact"></ol>
Step7
Added the following in app/res/xml/config.xml
<feature name="Contacts">
<param name="android-package" value="org.apache.cordova.contacts.ContactManager" />
</feature>
Step8
Added the following in app/AndroidManifest.xml
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
Step9
$ cordova run android
【问题讨论】:
-
你试过调试它吗?做
adb logcat的时候有没有报错? -
你在哪里调用 read_contacts 函数?到处都找不到。
-
你忘了粘贴吗?
-
我们如何调试 Cordova 项目? Eclispe-console-Logcat 输出:docs.google.com/document/d/…
-
另外我们把函数名从read_contacts改成了“onDeviceReady()”,问题依旧
标签: android cordova phonegap-plugins phonegap-build