Hello,
Summary (for those in a hurry to avoid having to read all): I am trying to understand where to find the information you use to make JavaObject working
Detailed question (for the most patient people)
The need of receiving the MEDIA_BUTTON press intent made me in need to understand the code kindly provided by Erel
In the same time, the Android's documentation tells us to register using the AUDIO_SERVICE
As I understand the B4A code :
Because, I don't understand why we call "audio" instead of "AUDIO_SERVICE", I have read the page about the AudioManager. Do we load all the information about the "audio" package ?
In Java they speak about
More, on the RemoteControlClient's page they specify the method "registerMediaButtonEventReceiver" is deprecated since api 5.0 and they advice to use the MediaSession's class. On that page, I find the new method to use "setMediaButtonReceiver".
And now, I am lost again while trying to replace the "RegisterForMediaButton" by "setMediaButtonReceiver" to test it on the emulator and check if one day I could use JavaObject alone instead of disturbing you everytime I need something sharp to be done. And boom : an error thrown.
Summary (for those in a hurry to avoid having to read all): I am trying to understand where to find the information you use to make JavaObject working
Detailed question (for the most patient people)
The need of receiving the MEDIA_BUTTON press intent made me in need to understand the code kindly provided by Erel
B4X:
Sub RegisterForMediaButton (ServiceName As String)
Dim am As JavaObject = GetContext.RunMethodJO("getSystemService", Array("audio"))
Dim component As JavaObject
component.InitializeNewInstance("android.content.ComponentName", Array(Application.PackageName, ServiceName.ToLowerCase))
am.RunMethod("registerMediaButtonEventReceiver", Array(component))
End Sub
Sub GetContext As JavaObject
Return GetBA.GetField("context")
End Sub
Sub GetBA As JavaObject
Dim jo As JavaObject
Dim cls As String = Me
cls = cls.SubString("class ".Length)
jo.InitializeStatic(cls)
Return jo.GetFieldJO("processBA")
End Sub
In the same time, the Android's documentation tells us to register using the AUDIO_SERVICE
B4X:
AudioManager am = mContext.getSystemService(Context.AUDIO_SERVICE);
...// Start listening for button presses
am.registerMediaButtonEventReceiver(RemoteControlReceiver);
...// Stop listening for button presses
am.unregisterMediaButtonEventReceiver(RemoteControlReceiver);
AudioManager am = mContext.getSystemService(Context.AUDIO_SERVICE);
As I understand the B4A code :
- GetBA returns our application "package's name" so it is not hard coded and can be used elsewhere
- GetContext returns the application's context so the system knows which app is acting
- RegisterForMediaButton registers the service associated with the app to the system. For example: com.b4x.sample/.serviceTest
Because, I don't understand why we call "audio" instead of "AUDIO_SERVICE", I have read the page about the AudioManager. Do we load all the information about the "audio" package ?
In Java they speak about
Use Context.getSystemService(Context.AUDIO_SERVICE) to get an instance of this class.
More, on the RemoteControlClient's page they specify the method "registerMediaButtonEventReceiver" is deprecated since api 5.0 and they advice to use the MediaSession's class. On that page, I find the new method to use "setMediaButtonReceiver".
And now, I am lost again while trying to replace the "RegisterForMediaButton" by "setMediaButtonReceiver" to test it on the emulator and check if one day I could use JavaObject alone instead of disturbing you everytime I need something sharp to be done. And boom : an error thrown.