2014-04-02 112 views
1

我正在尝试使用PhoneGap开发显示设备中的联系人列表。但它不显示联系人。PhoneGap-联系人未显示

既不显示任何类型的错误。

请任何人帮我找出在下面的代码中有什么不对,因为我在phonegap的begginer。

<!DOCTYPE HTML> 
<html> 
<head> 
<title> Contacts Demo </title> 
<script type="text/javascript" src="phonegap-1.1.0.js"></script> 
<script type="text/javascript"> 

    function init() 
    { 
     document.addEventListener("deviceready",onDeviceReady,false); 
    } 

    function onDeviceReady() 
    { 
     var options=new ContactFindOptions(); 
     options.filter=""; 
     var fields=["name","phoneNumbers"]; 
     navigator.service.contacts.find(fields,onSuccess,onError,options); 
    } 

    function onSuccess(contacts) 
    { 
     var ulr=document.getElementById("list"); 
     for(var i=0;i<contacts.length;i++) 
     { 
      var name=contacts[i].name.formatted; 
      var phoneNumber=contacts[i].phoneNumbers[0].value; 
      var li=document.createElement('li'); 
      li.innerHTML = "<a href=\"tel://"+phoneNumber+"\">"+name+"</a>"; 
      ulr=appendChild(li); 
     } 
    }; 

    function onError() 
    { 
     alert('onError!'); 
    }; 
</script> 
</head> 
<body> 
<h1>Contacts List</h1> 
<ul id="list"></ul> 
</body> 
</html> 

logcat的:

04-02 16:05:37.167: I/PhoneGapLog(7141): phonegap.xml missing. Ignoring... 
04-02 16:05:37.167: I/System.out(7141): loadUrl(file:///android_asset/www/contactindex.html) 
04-02 16:05:37.167: I/System.out(7141): url=file:///android_asset/www/contactindex.html baseUrl=file:///android_asset/www/ 
04-02 16:05:37.377: D/SoftKeyboardDetect(7141): We are in our onMeasure method 
04-02 16:05:37.377: D/SoftKeyboardDetect(7141): Old Height = 0 
04-02 16:05:37.377: D/SoftKeyboardDetect(7141): Height = 762 
04-02 16:05:37.377: D/SoftKeyboardDetect(7141): Old Width = 0 
04-02 16:05:37.377: D/SoftKeyboardDetect(7141): Width = 480 
04-02 16:05:37.377: D/SoftKeyboardDetect(7141): Ignore this event 
04-02 16:05:37.477: D/gralloc_goldfish(7141): Emulator without GPU emulation detected. 
04-02 16:05:37.657: D/SoftKeyboardDetect(7141): We are in our onMeasure method 
04-02 16:05:37.657: D/SoftKeyboardDetect(7141): Old Height = 762 
04-02 16:05:37.657: D/SoftKeyboardDetect(7141): Height = 762 
04-02 16:05:37.667: D/SoftKeyboardDetect(7141): Old Width = 480 
04-02 16:05:37.667: D/SoftKeyboardDetect(7141): Width = 480 
04-02 16:05:37.667: D/SoftKeyboardDetect(7141): Ignore this event 
04-02 16:05:38.698: E/SQLiteLog(7141): (14) cannot open file at line 30174 of [00bb9c9ce4] 
04-02 16:05:38.698: E/SQLiteLog(7141): (14) os_unix.c:30174: (2) open(/CachedGeoposition.db) - 
04-02 16:05:38.707: D/WebKit(7141): ERROR: 
04-02 16:05:38.707: D/WebKit(7141): SQLite database failed to load from /CachedGeoposition.db 
04-02 16:05:38.707: D/WebKit(7141): Cause - unable to open database file 
04-02 16:05:38.707: D/WebKit(7141): external/webkit/Source/WebCore/platform/sql/SQLiteDatabase.cpp(71) : bool WebCore::SQLiteDatabase::open(const WTF::String&, bool) 
04-02 16:05:38.907: D/PhoneGapLog(7141): null: Line 1 : XMLHttpRequest cannot load http://127.0.0.1:36419/01c9cf14-1235-4458-9b68-33a094aad126. Origin null is not allowed by Access-Control-Allow-Origin. 
04-02 16:05:38.917: E/Web Console(7141): XMLHttpRequest cannot load http://127.0.0.1:36419/01c9cf14-1235-4458-9b68-33a094aad126. Origin null is not allowed by Access-Control-Allow-Origin. at null:1 
04-02 16:05:38.987: D/PhoneGapLog(7141): file:///android_asset/www/phonegap-1.1.0.js: Line 930 : JSCallback Error: Request failed. 
04-02 16:05:38.997: I/Web Console(7141): JSCallback Error: Request failed. at file:///android_asset/www/phonegap-1.1.0.js:930 
04-02 16:05:39.218: D/PhoneGapLog(7141): file:///android_asset/www/phonegap-1.1.0.js: Line 769 : Error in success callback: Network Status1 = TypeError: Cannot read property 'contacts' of undefined 
04-02 16:05:39.218: I/Web Console(7141): Error in success callback: Network Status1 = TypeError: Cannot read property 'contacts' of undefined at file:///android_asset/www/phonegap-1.1.0.js:769 
04-02 16:05:39.347: D/dalvikvm(7141): GC_CONCURRENT freed 210K, 4% free 8192K/8455K, paused 18ms+5ms, total 58ms 

任何帮助将不胜感激。

谢谢。

+0

我从来没有与PhoneGap的编码,但是,看着你logcat的,它是说,你需要打开数据库。不确定,如果这是原因。 – DroidDev

+0

请任何人都可以帮助我? – GrIsHu

回答

0

您是否已将READ_CONTACTS权限添加到AndroidManifest.xml

代码:

<uses-permission android:name="android.permission.READ_CONTACTS" /> 

我建议你删除功能可按init(),只是让:

document.addEventListener("deviceready",onDeviceReady,false); 

原因的init()不会被触发。

如果你做所有的Phongap步骤,你没有得到错误,你必须尝试1最后认为在过去的作品,我为你节省你的项目数据,并做phonegap buildphonegap build app_platform

+0

是的,我已经提供了此权限。 – GrIsHu

+0

我将编辑我的答案 – Xdevelop

+0

现在看看 – Xdevelop

0

检查一下u'r PHONENUMBERS数组不为null