Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 732
Farid Farhat Avatar asked Feb 24 '12 13:02

Farid Farhat


1 Answers

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));
            }
        });
like image 136
tonymontana Avatar answered Nov 08 '22 21:11

tonymontana