Farid Farhat
Farid Farhat

Reputation: 2310

How to silence an incoming call

I am trying to silence an incoming call and prevent the BlackBerry device from ringing. I tried Alert.setVolume(0) and some EventInjector keys but this didn't work.

So how to silence an incoming call?

Upvotes: 7

Views: 974

Answers (4)

s5v
s5v

Reputation: 505

i am quite new to all this...but i thought i might as well put in my 2 cents worth...

i have been trying to find ways to programatically change the profile settings...

i have found that, while we cannot(yet) change the profile settings, we can change the setting that we are using( change the profile thats in use, i think)- this is something i came across searching for info-though i should give credit to alishaik786 for the code.

    public final class LoadingScreen extends MainScreen implements FieldChangeListener
    {   
        public LoadingScreen()
    {        
        createGUI();
    }

    private void createGUI() 
    {
        try 
        {           
            ApplicationManager.getApplicationManager().launch("net_rim_bb_profiles_app");
        } 
        catch (Exception e) 
        {
            //Exception
        }
    }

    public void fieldChanged(Field field, int context)
    {

    }   
}

Upvotes: 0

devnull
devnull

Reputation: 148

Some Blackberry phones have a mute key. You may try the following idea:

public void callIncoming(int callId) {
    if (KeyPad.hasMuteKey()) {
        /* Inject KEY_SPEAKERPHONE event */
    }
    else {
        /* Inject KEY_VOLUME_DOWN event N times, so that you get the mute effect */
    }
}

Upvotes: 2

tonymontana
tonymontana

Reputation: 5823

I was puzzled by your question and decided to take up the challenge. I tried different thing including

  1. Playing a "silence" audio file hoping to overlap the device's ringing or occupy the media player
  2. Hacking the phone screen via UiApplication.getUiApplication().getActiveScreen()
  3. Injecting keyboard events

Eventually, injecting VOLUME UP key (VOLUME DOWN key works as well) event worked for me and muted the device ringing on incoming call. The drawback with this approach is that sometimes the device did ring for a fraction of second before muting.

import net.rim.blackberry.api.phone.AbstractPhoneListener;
import net.rim.blackberry.api.phone.Phone;
import net.rim.device.api.system.Application;
import net.rim.device.api.system.EventInjector;
import net.rim.device.api.ui.Keypad;

class Muter extends AbstractPhoneListener {
    public void callIncoming(int callId) {          
        Thread muterThread = new Thread(new Runnable() {
            public void run() {
                EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN, (char) Keypad.KEY_VOLUME_UP, 0));
                EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_UP, (char) Keypad.KEY_VOLUME_UP, 0));
            }
        });
        muterThread.setPriority(Thread.MAX_PRIORITY);
        muterThread.start();
    }
}

public class MuterApp extends Application {
    public static void main(String[] args){
        Phone.addPhoneListener(new Muter());
        new MyApp().enterEventDispatcher();
    }
}

The following also works (replace Muter thread in callIncoming() method with the following code).

        UiApplication.getUiApplication().invokeLater(new Runnable() {
            public void run() {
                EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN, (char) Keypad.KEY_VOLUME_UP, 0));
                EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_UP, (char) Keypad.KEY_VOLUME_UP, 0));
            }
        });

Upvotes: 6

jprofitt
jprofitt

Reputation: 10964

You won't be able to disable the sound programmatically (found a couple other sources that said the same thing). The best workaround people have seemed to come up with was to use the EventInjector to change the phone's sound profile to silent.

Upvotes: 3

Related Questions