M Mostez Well-Known Member Licensed User Longtime User Jun 30, 2021 #1 I want to pass args to this sub (in QR reader example by @Johan Schoeman) to generate different tones as needed i.e. B4X: Jo.RunMethod("playTone", Array as int (streamType, volume)) B4X: #if Java import android.media.ToneGenerator; import android.media.AudioManager; public void playTone() { final ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100); tg.startTone(ToneGenerator.TONE_PROP_BEEP); } #End If How to do that? ToneGenerator reference: https://developer.android.com/reference/android/media/ToneGenerator
I want to pass args to this sub (in QR reader example by @Johan Schoeman) to generate different tones as needed i.e. B4X: Jo.RunMethod("playTone", Array as int (streamType, volume)) B4X: #if Java import android.media.ToneGenerator; import android.media.AudioManager; public void playTone() { final ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100); tg.startTone(ToneGenerator.TONE_PROP_BEEP); } #End If How to do that? ToneGenerator reference: https://developer.android.com/reference/android/media/ToneGenerator
Erel B4X founder Staff member Licensed User Longtime User Jun 30, 2021 #2 B4X: Dim p As Phone Dim tg As JavaObject tg.InitializeNewInstance("android.media.ToneGenerator", Array(p.VOLUME_NOTIFICATION, 100)) tg.RunMethod("startTone", Array(24, 1000)) Constants: https://developer.android.com/reference/android/media/ToneGenerator Upvote 0
B4X: Dim p As Phone Dim tg As JavaObject tg.InitializeNewInstance("android.media.ToneGenerator", Array(p.VOLUME_NOTIFICATION, 100)) tg.RunMethod("startTone", Array(24, 1000)) Constants: https://developer.android.com/reference/android/media/ToneGenerator
M Mostez Well-Known Member Licensed User Longtime User Jun 30, 2021 #3 thank you so much Erel, it works well, may I ask how to pass tg tone constant instead of number like B4X: tg.RunMethod("startTone", Array(ToneGenerator.TONE_PROP_BEEP, 100)) or should I create my own constants? Upvote 0
thank you so much Erel, it works well, may I ask how to pass tg tone constant instead of number like B4X: tg.RunMethod("startTone", Array(ToneGenerator.TONE_PROP_BEEP, 100)) or should I create my own constants?
Erel B4X founder Staff member Licensed User Longtime User Jul 1, 2021 #4 B4X: Dim tgc As JavaObject tgc.InitializeStatic("android.media.ToneGenerator") tg.RunMethod("startTone", Array(tgc.GetField("TONE_PROP_BEEP"), 100)) Upvote 0
B4X: Dim tgc As JavaObject tgc.InitializeStatic("android.media.ToneGenerator") tg.RunMethod("startTone", Array(tgc.GetField("TONE_PROP_BEEP"), 100))