2013-12-12 37 views
3

我在PhoneGap的-3.1.0 我想在我的應用程序中使用手機通訊錄上的Android應用程序的工作,所以我請參閱本Document.不能刪除聯繫人,Android的PhoneGap的

成功安裝插件接觸

當我刪除保存的聯繫人(通過JavaScript代碼保存),它提醒去除成功 但是當我進入接觸,現在還沒有從這裏取出,

每次我嘗試,它保存S上的接觸,但因爲像去除成功警報沒有不除,

我該怎麼辦...... 所以我需要它的幫助,爲什麼觸點不能刪除

回答

0

我已經創建了一個應用程序聯繫人插入和刪除Sample app

您可以叉GitHub上 - >xxbinxx/phoneGap-ContactsApp-Android。之後你肯定可以解決你的問題。 我已將聯繫人ID用於刪除目的。 這裏的短代碼...

var app ={ 
/********************SOME OTHER CODE*************************/ 
     openContacts: function() { 
     app.initialize(); 
     var options = new ContactFindOptions(); 
     options.filter = ""; 
     options.multiple = true; 
     var fields = ["*"]; //"*" will return all contact fields 
     navigator.contacts.find(fields, app.onSuccess, app.onError, options); 
    }, 
// Write contacts in DOM 
    onSuccess: function(contacts) { 
     var li = ''; 
     $.each(contacts, function(key, value) { 
      if (value.name) { 
       $.each(value.name, function(key, value) { 
        if (key === 'formatted') { 
         name = value; 
        } 
       }); 
      } 
      if (value.note) { 
       note = value.note; 
      } 
      if (value.id) { 
       id = value.id; 
      } 
      console.log("id : " + id + "-> name : " + name + " -> note : " + note); 
      li += '<li style="text-decoration:none;"><b>Name</b>: ' + name + '<div class="removeIcon pullRight" onclick="app.removeThisContact(\'' + id + '\',\'' + name + '\')">&nbsp;</div><br><b> Note:</b> ' + note + '</li>'; 
     }); // NOTICE the ID is passed as PARAMETER to remove specific contact. 
     $("#contact").html(li); 
    }, 
    onError: function(contactError) { 
     alert('onError!' + contactError.code); 
    }, 
    removeThisContact: function(id, name) { 
     console.log("removing contact : " + name);  
     options = new ContactFindOptions(); // find the contact to delete 
     options.filter.id = id; 
     options.multiple = "true"; 
     var fields = ["displayName", "name"]; // you can take any.. 
     navigator.contacts.find(fields, deleteThis, app.onError, options); 

     function deleteThis(contacts) { 
      var contact = contacts.pop(); 
// logging things to troubleshoot. 
      console.log('inside deleteThisContact: parameter passed: '+ contacts); 
      console.log("popped out:" +contact); 
       contact.remove(function() { 
        $('#status-area') 
        .flash_message({ 
         text: 'Contact Removed!', 
         how: 'append' 
        }); 
        app.openContacts(); 
       }, null);   
     }, 
    deleteAllTheContacts: function() { 
     var deleteContact = function(contacts) { 
      console.log("length = " + contacts.length); 
      // No contacts left, stop saving 
      if (contacts.length == 0) { 
       console.log("All contacts removed"); 
       return; 
      } 

      var contact = contacts.pop(); 


contact.remove(function() { 
       deleteContact(contacts); 
      }, null); 
     }; 

     navigator.contacts.find(["*"], deleteContact, app.onError, { 
      "multiple": true 
     }); 
    }, 
/********************SOME OTHER CODE*************************/ 
    } 
$.fn.flash_message = function(options) { 
    //flash your message 
} 

希望這會幫助你。 :)

+0

我在更新github上的文件時遇到問題...更新的回購將在24小時內提供。謝謝 – xxbinxx

+0

完整的包現在可用.. https://github.com/xxbinxx/phoneGap-ContactsApp-Android – xxbinxx