#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim myMusic As MediaPlayer
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
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")
Dim l As Label
l.Initialize("l")
l.Color = Colors.Black
l.Textcolor = Colors.White
l.TextSize = Activity.Height/10
Activity.AddView(l,0,0,Activity.Width,Activity.Height)
l.Text = "wired: " & isWiredHeadsetOn & _
CRLF & _
"Speaker: " & isSpeakerphoneOn
If FirstTime Then
myMusic.Initialize2("myMusic")
End If
playaudio
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub isWiredHeadsetOn As Boolean
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
Return r.RunMethod("isWiredHeadsetOn")
End Sub
Sub setWiredHeadsetOn As Boolean
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
Return r.RunMethod2("setWiredHeadsetOn", True, "java.lang.boolean")
End Sub
Sub isSpeakerphoneOn As Boolean
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
Return r.RunMethod("isSpeakerphoneOn")
End Sub
Sub playaudio
ToastMessageShow("Play audio", True)
myMusic.Load(File.DirAssets, "boom.mp3")
myMusic.Play
End Sub
Sub myMusic_Complete
ToastMessageShow("Retry", True)
setWiredHeadsetOn
myMusic.Play
End Sub