Android Question Delete contact SIMCARD

Discussion in 'Android Questions' started by MarcoRome, Mar 7, 2015.

  1. MarcoRome

    MarcoRome Expert Licensed User

    Hi all.
    I have this code:

    Code:
    'Cancella
    'Deletes the contact with the given name.
    Sub DeleteContactByName(Name As String)
    '***********This Delete number to Contact  and work 
       Dim u As Uri
       u.Parse(
    "content://com.android.contacts/data")
       
    Dim crsr As Cursor = cr.Query(u, Array As String("_id""raw_contact_id"), _
          
    "mimetype = ? AND data1 = ?"Array As String("vnd.android.cursor.item/name", Name), "")
       
    For i = 0 To crsr.RowCount - 1
          crsr.Position = i
          
    Dim rawId As Long = crsr.GetLong("raw_contact_id")
          
    Log(cr.Delete(u, "raw_contact_id = ?"Array As String(rawId)))
          
    Dim u2 As Uri
          u2.Parse(
    "content://com.android.contacts/raw_contacts")
          
    Log(cr.Delete(u2, "_id = ?"Array As String(rawId)))
       
    Next
       crsr.Close
    '******** End Delete number to contact
      
    '*********** This Delete number to Sim
       Dim simUri As Uri
       simUri.Parse(
    "content://icc/adn")
       
    Dim crsr1 As Cursor = cr.Query(simUri, Array As String("_id","name","number"), "name = ?"Array As String(Name), "")
       
    For i = 0 To crsr1.RowCount - 1
          crsr1.Position = i
          
    Dim rawId1 As Long = crsr1.GetLong("_id")
               
    Log(cr.Delete(simUri, "_id = ?"Array As String(rawId1))) 
          
    Next
       crsr1.Close
    '********** End Delete number to Sim
     'Rileggo i dati
       ListView2.Clear
       ReadSimContacts
    End Sub


    Now this code works ( '***********This Delete number to Contact and work ) and delete numbers from phone contacts, in each case in the memory of the sim are still present. Then use the second piece of code ('*********** This Delete number to Sim) donw work and also:
    1) also i have "where" in the query with the name, returned 3 records (all existing contacts on the sim)
    2) Do not perform any data deletion

    Any idea or solution ??
    Thanik you
    Marco
     
  2. MarcoRome

    MarcoRome Expert Licensed User

    I found also this documentation:

    https://simsalabim.googlecode.com/svn-history/r7/trunk/src/at/fhj/swd07/simsalabim/SimUtil.java

    seem that Resolver have bug ( // TODO: currently this always returns ALL contacts on the SIM. Is this a bug in the content provider? ):

    Code:
    public int deleteContact(Contact contact) {
            // check, that only one 
    contact with this identifiers existing
            // TODO: currently this always returns ALL 
    contacts on the SIM. Is this a bug in the content provider?
    //        
    Cursor results = resolver.query(simUri, new String[]{android.provider.BaseColumns._ID}, "tag='"+contact.name+"' AND number='"+contact.number+"'", null, null);
    //        int rowCount = results.getCount();
    //        if (rowCount > 1) {
    //            return rowCount;
    //        }
          
            // TODO: Can this ever return >1 after check above?
            int deleteCount = resolver.delete(simUri, "tag='"+contact.name+"' AND number='"+contact.number+"'", null);
            if(deleteCount != 1) {
                return -1;
            }
          
            return 0;
        }
     
    Rockefeller Goldman likes this.
  3. Erel

    Erel Administrator Staff Member Licensed User

    You must add the number to the where field (and possibly the tag field as well).
     
    Rockefeller Goldman likes this.
  4. MarcoRome

    MarcoRome Expert Licensed User

    Hi Erel also so dont work
    Code:
    ...
    ritorna = cr.Delete(simUri, 
    "tag = ? AND number = ?"Array As String(Name, numero_telefono_cancello))
    ...
     
    Rockefeller Goldman likes this.
  5. Erel

    Erel Administrator Staff Member Licensed User

    What is the value of ritorna?
     
    Rockefeller Goldman likes this.
  6. MarcoRome

    MarcoRome Expert Licensed User

    0
     
    Rockefeller Goldman likes this.
  7. Erel

    Erel Administrator Staff Member Licensed User

    Sim card contacts access is based on non-public API. Try to find Java code that is supposed to work and I can help you translate it to B4A.
     
  8. MarcoRome

    MarcoRome Expert Licensed User

    Ok Erel. Thank you very much
     
    Rockefeller Goldman likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice