How to access contacts on the SIM card?

Der Mond

Member
Licensed User
Longtime User
Hello everyone,
I tried to read the list of the contacts of the SIM with the command "My_Contacts.GetAll" but I can just see the internal list.
How can I read all contacts (SIM + INTERNAL)?

Sorry for my poor English:sign0013:

Thank you for everything

Vincenzo
 
Last edited:

Der Mond

Member
Licensed User
Longtime User
Thank you for your replay.
I am waiting for the new release.

See you

Vincenzo
 
Upvote 0

pappicio

Active Member
Licensed User
Longtime User
Hello everyone,
I tried to read the list of the contacts of the SIM with the command "My_Contacts.GetAll" but I can just see the internal list.
How can I read all contacts (SIM + INTERNAL)?

Sorry for my poor English:sign0013:

Thank you for everything

Vincenzo
this is a java code to read sim card contacts, I don't know if it works, but you can try it!

B4X:
public List ReadAllSimContact()
  {
 List list = new List();
    list.Initialize();
    try
    {
        String m_simPhonename = null; 
        String m_simphoneNo = null;

        Uri simUri = Uri.parse("content://icc/adn"); 
        Cursor cursorSim = this.getContentResolver().query(simUri,null,null,null,null);

        Log.i("PhoneContact", "total: "+cursorSim.getCount());

        while (cursorSim.moveToNext()) 
        {      
            m_simPhonename =cursorSim.getString(cursorSim.getColumnIndex("name"));
            m_simphoneNo = cursorSim.getString(cursorSim.getColumnIndex("number"));
            m_simphoneNo.replaceAll("\\D","");
            m_simphoneNo.replaceAll("&", "");
            m_simPhonename=m_simPhonename.replace("|","");
            list.add(m_simPhonename +","+m_simphoneNo);
            Log.i("PhoneContact", "name: "+m_simPhonename+" phone: "+m_simphoneNo);
        }        
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
   cursorSim.close;
   return list;
}
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Now that we have the ContentResolver library you can convert this code:
B4X:
Sub ReadSimContacts
   Dim simUri As Uri
   simUri.Parse("content://icc/adn")
   Dim crsr As Cursor = cr.Query(simUri, Null, "", Null, "")
   For i = 0 To crsr.RowCount - 1
      crsr.Position = i
      Log(crsr.GetString("name"))
      Log(crsr.GetString("number"))
   Next
   crsr.Close
End Sub
 
Upvote 0

Ramezanpour2

Member
Licensed User
Longtime User
@Erel


hi erel in the this code that you write here

Sub ReadSimContactsDim simUri AsUri
simUri.Parse("content://icc/adn")Dim crsr AsCursor = cr.Query(simUri, Null, "", Null, "")For i = 0To crsr.RowCount - 1
crsr.Position = iLog(crsr.GetString("name"))Log(crsr.GetString("number"))Next
crsr.CloseEnd Sub

what is the cr??

im want to get list of sim contacts on app
 
Upvote 0
Top