I'm using the "GetBA" method that @Erel has posted here in the forums several times to get the BA context in order to play a system sound effect. The method works fine in a class as long as the class' "caller" is an activity. If I instantiate the class playing the sound effect inside another class (which is instantiated from an activity) the GetBA method fails with a "class not found" exception.
I don't know enough about how the underlying Java works or how the BA process is structured to make an informed guess as to how to fix this. How can I modify the GetBA routine so it will work with a class hosted both on an Activity and from inside another class?
I don't know enough about how the underlying Java works or how the BA process is structured to make an informed guess as to how to fix this. How can I modify the GetBA routine so it will work with a class hosted both on an Activity and from inside another class?
Play system sounds methods:
Private Sub PlayDefaultClick
'moCaller is the "callback" object and may be an Activity or another class...
If moCaller <> Null Then
PlaySoundEffect(0) 'FX_KEY_CLICK
End If
End Sub
Private Sub PlayKeypressStandard
If moCaller <> Null Then
PlaySoundEffect(5) 'FX_KEYPRESS_STANDARD
End If
End Sub
Private Sub PlaySoundEffect(SoundEffectConstant As Int)
Dim am As JavaObject = GetContext.RunMethod("getSystemService", Array("audio"))
am.RunMethod("playSoundEffect", Array(SoundEffectConstant))
End Sub
Private Sub GetContext As JavaObject
Return GetBA.GetField("context")
End Sub
Private Sub GetBA As JavaObject
Dim jo As JavaObject
Dim cls As String = moCaller
cls = cls.SubString("class ".Length)
jo.InitializeStatic(cls) 'fails with "class not found" exception when moCaller is another class.
Return jo.GetFieldJO("processBA")
End Sub