0

私はアンドロイド5以上の上で動作しますが、アンドロイド4 OSにはできませんが、電話から連絡先を読み取るアンドロイドアプリ(phonegap)に取り組んでいます電話からの連絡先を読んで、phonegapでcontacts.findを使って作業しているときに誰かがこの問題を経験したかどうか尋ねたいと思う。contacts.find does not work andandriod 4(phonegap)

document.addEventListener("deviceready", onDeviceReady, true); //the onDeviceReady function takes place when the app starts 
 

 
function onDeviceReady() { 
 
// find all contacts displayName, Name and phoneNumbers 
 
var fields  = ["displayName", "name", "phoneNumbers"]; 
 
var options  = new ContactFindOptions(); 
 
options.filter = ""; 
 
options.multiple = true; 
 
navigator.contacts.find(fields, onSuccess, onError, options); 
 
\t var currentdate = new Date(); 
 
    var datetime = currentdate.getDate() + "-"+(currentdate.getMonth()+1) 
 
    + "-" + currentdate.getFullYear() + "T" + currentdate.getHours() + ":" 
 
    + currentdate.getMinutes() + ":" + currentdate.getSeconds(); 
 
\t alert(datetime); 
 
} \t

+0

あなたはコードスニペットを投稿することができますか? –

+0

ちょうどそれを今投稿しました –

答えて

0

私はあなたのためのサンプルを作成し、Androidのバージョン4.1.1、4.2.2でテストされ、4.4.4およびそれは完全に正常に動作。

コードが

は、まず cordova plugin add cordova-plugin-contacts

プラグイン連絡先を追加し、その後のindex.htmlで書く::ある::

<body> 
    <h2>Contacts List</h2> 
    <div id="mobile"></div> 
    <div id="email"></div> 

    <script src="cordova.js"></script> 

    <script type="text/javascript"> 
     document.addEventListener("deviceready", init, false); 
     function init() { 
      navigator.contacts.find([navigator.contacts.fieldType.displayName],gotContacts,errorHandler); 
     } 

     function errorHandler(e) { 
      console.log("errorHandler: "+e); 
     } 

     function gotContacts(c) { 
      console.log("gotContacts, number of results "+c.length); 

      mobileDiv = document.querySelector("#mobile"); 
      emailDiv = document.querySelector("#email"); 

      /* Retriving phoneNumbers */ 
      for(var i=0, len=c.length; i<len; i++) { 
       if(c[i].phoneNumbers && c[i].phoneNumbers.length > 0) { 
        mobileDiv.innerHTML += "<p>"+c[i].displayName+"<br/>"+c[i].phoneNumbers[0].value+"</p>"; 
       } 
      } 

      /* Retriving Email */ 
      for(var i=0, len=c.length; i<len; i++) { 
       if(c[i].emails && c[i].emails.length > 0) { 
        emailDiv.innerHTML += "<p>"+c[i].emails[0].value+"</p>"; 
       } 
      } 
     } 
    </script> 
</body> 

+0

私はあなたとあなたを試してみましょう –

+0

私は、document.addEventListener( "deviceready"、init、false)のuseCaptureに気付きました。特別な理由はありますか?falseに設定されていますか? –

+0

No. コードには何の影響もありません。 – Hiten