Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a beep in android?

Tags:

android

I would like my app beep with a specific frequency and duration. In the windows equivalent of this app (written in c#) I used a c++ dll with the function

beep(frequency, duration);  

Is this the same in android? Or at least how can I put my c++ dll in the project?

I would prefer not to use pre-built mp3's or system sound because I would like to give the user the choice of the frequency and duration.

like image 953
Cippo Avatar asked Aug 28 '12 07:08

Cippo


People also ask

Why does my phone make a beep sound?

It may be some kind of notification from one of your recent downloaded app or any app which is set to remind you something. try to uninstall your recent downloaded app and when you here the beeping immediately check for the running app or if any notification is there.


2 Answers

I tried amine.b's answer. In short, to play a loud Beep sound:

ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_ALARM, 100); toneG.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 200);  
like image 137
Eng. Samer T Avatar answered Sep 19 '22 11:09

Eng. Samer T


The easy way is to use instance of ToneGenerator class:

// send the tone to the "alarm" stream (classic beeps go there) with 50% volume ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_ALARM, 50); if (val >= taux_max) {     taux_text.setTextColor(warnning_col);     toneG.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 200); // 200 is duration in ms } 

Please refer to the documentation of ToneGenerator and AudioManager for exact meaning of parameters and possible configuration of the generator.

like image 22
amine.b Avatar answered Sep 21 '22 11:09

amine.b