2
private fun addContactToSim(number:String,name:String) {
    try {        
        val simUri = Uri.parse("content://icc/adn")
        val values = ContentValues()
        values.put("number", number)
        values.put("tag", name)
        context.getContentResolver().insert(simUri, values)
    }
    catch (e:Exception)
    {
        e.printStackTrace()
    }
}

This function I am using to create contact to sim am calling this function in onCreate() with single contact addContactToSim("MyTestNumber","9028340932") like this but contact is not saving to sim I am unable to see contact in sim please suggest me what I am doing wrong.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Manoj Kumar
  • 97
  • 1
  • 1
  • 10

1 Answers1

0

Use ContentValues for creating contact in phone.have look:

Uri simUri = Uri.parse("content://icc/adn");
ContentValues cv = new ContentValues();
cv.put("tag", "Hey");
cv.put("number", "1234567890");
getContentResolver().insert(simUri, cv);
getContentResolver().notifyChange(simUri, null);

also add permission in Manifest:

<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
Hemant Parmar
  • 3,924
  • 7
  • 25
  • 49