I was puzzled by your question and decided to do it. I have tried various things including
- Play a sound file of "silence", hoping to block the device, calling or occupying a media player.
- Hacking the phone screen via
UiApplication.getUiApplication().getActiveScreen() - Keyboard event injection
In the end, when you press the VOLUME UP button (VOLUME DOWN key), an event is triggered, and the device mutes the ringtone on an incoming call. The disadvantage of this approach is that sometimes the device performed the ring for a second before muffling.
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 the Muter stream in callIncoming() with the following code method).
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)); } });
mrvincenzo
source share