#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
Dim cu As ContactsUtils
End Sub
Sub Globals
Dim lstContacts As ListView
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
cu.Initialize
End If
lstContacts.Initialize("lstContacts")
Activity.AddView(lstContacts, 0, 0, 100%x, 100%y)
For Each c As cuContact In cu.FindAllContacts(True)
lstContacts.AddSingleLine2(c.DisplayName, c)
Next
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub lstContacts_ItemLongClick (Position As Int, Value As Object)
Dim c As cuContact = Value
cu.SetCustomRingtone(c.Id, GetPathFromContentResult(File.Combine(File.DirRootExternal, "ringtone.mp3")))
End Sub
Sub GetPathFromContentResult(UriString As String) As String
If UriString.StartsWith("/") Then Return UriString 'If the user used a file manager to choose the image
Dim Proj() As String
Proj = Array As String("_data")
Dim Cursor As Cursor
Dim r As Reflector
Dim Uri As Object
Uri = r.RunStaticMethod("android.net.Uri", "parse", _
Array As Object(UriString), _
Array As String("java.lang.String"))
r.Target = r.GetContext
r.Target = r.RunMethod("getContentResolver")
Cursor = r.RunMethod4("query", _
Array As Object(Uri, Proj, Null, Null, Null), _
Array As String("android.net.Uri", _
"[Ljava.lang.String;", "java.lang.String", _
"[Ljava.lang.String;", "java.lang.String"))
Cursor.Position = 0
Dim res As String
res = Cursor.GetString("_data")
Cursor.Close
Return res
End Sub