Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim hg As PhoneEvents
Dim RM As RingtoneManager
Dim jo As JavaObject
Dim jo2 As JavaObject
Dim u As Uri
Dim chosenRingTone As String
Private lbl_batterylevel As Label
Private btn_setringtone As Button
Private btn_playringtone As Button
Private btn_isplaying As Button
Private btn_stopringtone As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout1")
hg.Initialize("hg")
jo.InitializeStatic("android.media.RingtoneManager")
jo2.InitializeContext
u.Parse("content://media/internal/audio/media/31")
Log(RM.GetDefault(RM.TYPE_RINGTONE))
jo2 = jo.RunMethodJO("getRingtone", Array(jo2, u))
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub RM_PickerResult (Success As Boolean, Uri As String)
Log(Uri)
chosenRingTone = Uri
If Success Then
Dim R As Reflector
'Convert the selected Uri string to a Uri Object compatible with the getRingtone method.
Dim RTUri As Object = R.RunStaticMethod("android.net.Uri","parse",Array As Object(Uri),Array As String("java.lang.String"))
'Get the actual ringtone object from the Uri
R.Target = R.RunStaticMethod("android.media.RingtoneManager","getRingtone",Array As Object(R.GetContext,RTUri),Array As String("android.content.Context","android.net.Uri"))
'Get the title from the ringtone object
Dim Name As String = r.RunPublicmethod("getTitle",Array As Object(R.GetContext),Array As String("android.content.Context"))
'Silent returns Unknown ringtone
Log("RingToneName="&Name)
Else
Log("Pickerresult Error")
End If
End Sub
Sub btn_setringtone_Click
RM.ShowRingtonePicker("RM",RM.TYPE_RINGTONE,True,chosenRingTone)
End Sub
Sub btn_playringtone_Click
If jo2.RunMethod("isPlaying",Null) Then
Log("Toggle stop")
jo2.RunMethod("stop",Null)
Else
Log("Toggle Play")
jo2.RunMethod("play",Null)
End If
End Sub