I've got the following data class:
data class Contact(
val id : String,
val name : String,
val number : String)
I now want to add a Contact to the Contact list of the phone using a method inside a BoundService. I've got the following code right now:
fun importContact(Contact: Contact) {
val intent = Intent(ContactsContract.Intents.Insert.ACTION)
intent.type = ContactsContract.RawContacts.CONTENT_TYPE
intent.putExtra(ContactsContract.Intents.Insert.NAME, Contact.name)
intent.putExtra(ContactsContract.Intents.Insert.PHONE, Contact.number)
startActivity(intent)
}
However as this method is run inside a BoundService it throws me the following Exception:
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
How can I solve this problem?