Android Question Custom ringtone not work

Lakhtin_V

Active Member
Licensed User
Longtime User
My application adds to the contact list of user. I want incoming calls from these user to play a non-standard melody. New user appear in the contact list. After I use the service SetCustomRingtone from the class ContactsUtils to set a custom ringtone. The process runs without errors, but these users in contacts have no any things ringtone. For all the play standart ringtone.

in class module...
B4X:
'Inserts a new contact and returns the cuContact object of this contact.
Public Sub InsertContact(Name As String, Phone As String, Email As String, Note As String, Company As String) As cuContact
    Dim values As ContentValues
    values.Initialize
    values.PutNull("account_name")
    values.PutNull("account_type")
  
    Dim rawUri As Uri = cr.Insert(rawContactUri, values)
    Dim rawContactId As Long = rawUri.ParseId
  
    values.Initialize
    values.PutLong("raw_contact_id", rawContactId)
    values.PutString("mimetype", "vnd.android.cursor.item/phone_v2")
    values.PutString("data1", Phone)
    cr.Insert(dataUri, values)
  
    values.Initialize
    values.PutLong("raw_contact_id", rawContactId)
    values.PutString("mimetype", "vnd.android.cursor.item/name")
    values.PutString("data1", Name)
    cr.Insert(dataUri, values)

    values.Initialize
    values.PutLong("raw_contact_id", rawContactId)
    values.PutString("mimetype", "vnd.android.cursor.item/email_v2")
    values.PutString("data1", Email)
    cr.Insert(dataUri, values)
  
    values.Initialize
    values.PutLong("raw_contact_id", rawContactId)
    values.PutString("mimetype", "vnd.android.cursor.item/note")
    values.PutString("data1", Note)
    cr.Insert(dataUri, values)
  
    values.Initialize
    values.PutLong("raw_contact_id", rawContactId)
    values.PutString("mimetype", "vnd.android.cursor.item/organization")
    values.PutString("data1", Company)
    cr.Insert(dataUri, values)
  
    Dim cu As cuContact
    cu.Initialize
    Dim crsr As Cursor = cr.Query(dataUri, Array As String("contact_id", "display_name"), "raw_contact_id = ?", _
        Array As String(rawContactId), "")
    crsr.Position = 0
    cu.DisplayName = crsr.GetString("display_name")
    cu.Id = crsr.GetLong("contact_id")
'  
'    Dim values As ContentValues
'    values.Initialize
'    values.PutString("custom_ringtone", RingtoneURI)
'    cr.Update(contactUri, values, "_id = ?", Array As String(Id))
''    Log("MP3  " & RingtoneURI)

    Return cu
  
End Sub

in activity module...
B4X:
    Cont=Main.CU.InsertContact("VALERA", "+77013503350", "[email protected]", "GURU", "INFORMBYURO")
    strPath=GetPathFromContentResult(File.Combine(File.DirInternal,"rington.mp3"))
    Main.CU.SetCustomRingtone(Cont.Id, strPath)
 

Lakhtin_V

Active Member
Licensed User
Longtime User
In the new contact, the custom ringtone field does not appear . Probably not working procedure in class module.
B4X:
Public Sub SetCustomRingtone (Id As Long, RingtoneURI As String)
    Dim values As ContentValues
    values.Initialize
    values.PutString("custom_ringtone", RingtoneURI)
    cr.Update(contactUri, values, "_id = ?", Array As String(Id))
'    Log("MP3  " & RingtoneURI)
End Sub

There may be a problem in what event you need to use an SET(Update) or Add(Insert)? In the contacts that my application generates there is no any ringtone, so I need to use Add(Insert) action, but I do not know how to do it

B4X:
Public Sub AddCustomRingtone (Id As Long, RingtoneURI As String)
    Dim values As ContentValues
    values.Initialize
    values.PutString("custom_ringtone", RingtoneURI)
'    cr.Update(contactUri, values, "_id = ?", Array As String(Id))
    cr.Insert(contactUri, values)
End Sub
 
Last edited:
Upvote 0

Lakhtin_V

Active Member
Licensed User
Longtime User
Last edited:
Upvote 0
Top