Problem with android microphone

I created android application that able to draw wave from input sound( real time).It works very well on the first test in Xcode So I try it on android but it doesnt work.


maybe this is problem about android microphone ?

pls help 


Can you be clearer on "Doesn't Work", please?

Did you add permission for your app to access the mic?

Does it crash? {Did you include Native support?}



It can draw wave normally when i run simulation in Xcode , but it can't draw any wave in Android Phone . 

I think that's even less clear than your original message!

You need to ask better questions if you want people to help - it's impossible for anyone to know what's going on if you're so vague.

sorry for my vague . i will try better .

It doesn't have any crash problem , and i don't sure about mic permission ( im so new with this ).

but here is my code ... 

ps. drawwave is new object from wavedisplay class that will auto draw wave from mic .




    setSize (600, 400);


    if(deviceManager== nullptr){

    deviceManager = new AudioDeviceManager();

    deviceManager->initialise(2, 2, NULL , true);



    deviceManager->addAudioCallback (&wave);




      deviceManager->removeAudioCallback (&wave);


void MainContentComponent::paint (Graphics& g)


    g.fillAll (Colour (0xff001F36));

    g.setFont (Font (16.0f));

    g.setColour (Colours::white);

   // g.drawText ("FinalProject V.0.2", getLocalBounds(), Justification::centred, true);


void MainContentComponent::resized()


    Rectangle<int> area (getLocalBounds());

    drawwave.setBounds (area.removeFromTop (80).reduced (8));


here is code from wavedisplay class 


class WaveDisplay  : public Component,

public AudioIODeviceCallback,

private Timer




    : nextSample (0), subSample (0), accumulator (0)


        setOpaque (true);



        startTimerHz (75); // use a timer to keep repainting this component




    void audioDeviceAboutToStart (AudioIODevice*) override





void audioDeviceStopped() override




void audioDeviceIOCallback (const float** inputChannelData, int numInputChannels,

                            float** outputChannelData, int numOutputChannels,

                            int numSamples) override


for (int i = 0; i < numSamples; ++i)


    float inputSample = 0;


    for (int chan = 0; chan < numInputChannels; ++chan)

        if (inputChannelData[chan] != nullptr)

            inputSample += std::abs (inputChannelData[chan][i]);  // find the sum of all the channels


            pushSample (10.0f * inputSample); // boost the level to make it more easily visible.


// We need to clear the output buffers before returning, in case they're full of junk..

for (int j = 0; j < numOutputChannels; ++j)

if (outputChannelData[j] != nullptr)

zeromem (outputChannelData[j], sizeof (float) * (size_t) numSamples);



float samples[1024];

int nextSample, subSample;

float accumulator;

void clear()


    zeromem (samples, sizeof (samples));

    accumulator = 0;

    subSample = 0;


void paint (Graphics& g) override


g.fillAll (Colours::black);

const float midY = getHeight() * 0.5f;

int samplesAgo = (nextSample + numElementsInArray (samples) - 1);

RectangleList<float> waveform;

waveform.ensureStorageAllocated ((int) numElementsInArray (samples));

for (int x = jmin (getWidth(), (int) numElementsInArray (samples)); --x >= 0;)


    const float sampleSize = midY * samples [samplesAgo-- % numElementsInArray (samples)];

    waveform.addWithoutMerging (Rectangle<float> ((float) x, midY - sampleSize, 1.0f, sampleSize * 2.0f));


g.setColour (Colours::lightgreen);

g.fillRectList (waveform);


void timerCallback() override




void pushSample (const float newSample)


    accumulator += newSample;


    if (subSample == 0)


        const int inputSamplesPerPixel = 200;


        samples[nextSample] = accumulator / inputSamplesPerPixel;

        nextSample = (nextSample + 1) % numElementsInArray (samples);

        subSample = inputSamplesPerPixel;

        accumulator = 0;









I'll ignore the code for the moment - Have you tried to build the demo app for Android, and do the Audio demos work OK?

Especially, see the Android part of the Introjucer project, where it has a check-box for Audio Input Required...

Check your own app has that box checked...

1 Like

oh wow . thanks a lot . 

works so great ! 



When I build and open the demo in android studio and download into my smartphone, everything seems to work fine but audio suff, the app is automatically restarted everytime I select any audio feature in the (left column) menu: Audio:FilePayback/LatencyDetector/Recording/Synthesisers/MIdi

Is it because the demo code is not supported for Android?I would like to record and play audio. O please tell me an example to start with.


Thanks in advance.





No problems like that on our devices here.. Which android device/OS version have you got?



I am using Android version 4.2.2 (Smartphone is   BQ Aquaris).

I downloaded the last projuce version and compiling with VS2015, I installed API17 to run the app on this Android version.






[EDITED]. I forgot to enable the "Audio Record permission in the manifest" field!!It works flawless now!! wink

I have found out now that, when I turn the smartphone around (vertical/horizontal or viceversa) the demo application is restarted and the welcome menu selected, and it stops recording or whatever the demo was doing.


We fixed this a few days ago - pull the latest version.

Ohh, great!


What a coincidence!-




FORGET, it is also resolved in JUCE4.1 ;D



I didn't know if opening a new post, but it is a simple question

I have realised, when an app is running in android, when either "home" button (exit to desktop), or the ONOFF button (sleep mode?? - the screen turns black) the application is also there any option to avoid that and keep the app running??




No.. I think you're at the mercy of the OS in terms of stopping/starting the app.