Sub Process_Globals
Dim rm As RingtoneManager
Dim ringtone As JavaObject
Dim rt As JavaObject
Dim ion As Object
Dim dzw As String
End Sub
Sub Globals
Private Button1 As Button
Private Button2 As Button
Private Button3 As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click 'plya ring
PlayRingtone(rm.GetDefault(rm.TYPE_NOTIFICATION))
End Sub
Sub Button2_Click 'stop plya
stop_plya
End Sub
Sub Button3_Click 'Ring selection
ShowPicker
End Sub
Sub PlayRingtone(url As String)
url=dzw
Dim jo As JavaObject
jo.InitializeStatic("android.media.RingtoneManager")
Dim jo2 As JavaObject
jo2.InitializeContext
Dim u As Uri
u.Parse(url)
ringtone = jo.RunMethodJO("getRingtone", Array(jo2, u))
rt=ringtone
ringtone.RunMethod("play", Null)
End Sub
Sub stop_plya
Dim jo As JavaObject
jo.InitializeStatic("android.media.RingtoneManager")
Dim jo2 As JavaObject
jo2.InitializeContext
Dim u As Uri
u.Parse(rm.GetDefault(rm.TYPE_RINGTONE))
ringtone =jo.RunMethodJO("getRingtone", Array(jo2, u))
ringtone.RunMethod("stop", Null)
End Sub
'**************************************** Procedures for selecting the ringing tone *******************************************
Sub StartActivityForResult(i As Intent)
Dim jo As JavaObject = GetBA
ion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "ion", Null)
jo.RunMethod("startActivityForResult", Array As Object(ion, i))
End Sub
Sub GetBA As Object
Dim jo As JavaObject
Dim cls As String = Me
cls = cls.SubString("class ".Length)
jo.InitializeStatic(cls)
Return jo.GetField("processBA")
End Sub
Sub ion_Event (MethodName As String, Args() As Object) As Object
If Args(0) = -1 Then 'resultCode = RESULT_OK
Dim i As Intent = Args(1)
Dim jo As JavaObject = i
Dim uri As String = jo.RunMethod("getParcelableExtra", _
Array As Object("android.intent.extra.ringtone.PICKED_URI"))
Log(uri)
dzw = uri
End If
Return Null
End Sub
''************************* wywołanie wybór dzwonków**************************
Sub ShowPicker
Dim i As Intent
i.Initialize("android.intent.action.RINGTONE_PICKER", "")
i.PutExtra("android.intent.extra.ringtone.TYPE", 1)
StartActivityForResult(i)
End Sub