Code example for ToneGenerator

Methods: release, sleep, startTone, stopTone

0
        ToneGenerator toneGen2;
        int type;
        boolean result = true;
 
        toneGen1 = new ToneGenerator(AudioManager.STREAM_MUSIC, 100);
        toneGen2 = new ToneGenerator(AudioManager.STREAM_MUSIC, 50);
 
        if (toneGen1.startTone(ToneGenerator.TONE_DTMF_1)) {
            Thread.sleep(100);
            if (toneGen2.startTone(ToneGenerator.TONE_DTMF_2)) {
                Thread.sleep(500);
                toneGen1.stopTone();
                Thread.sleep(100);
                toneGen2.stopTone();
            } else { 
                toneGen1.stopTone();
                result = false;
            } 
        } else { 
            result = false;
        } 
 
        toneGen1.release();
        toneGen2.release();
        return result;
    } 
 
    // Test start of new tone without stopping previous one  
    public static boolean tonesStressTest() throws Exception {