我正在尝试静音来电并阻止BlackBerry设备响铃.我尝试了Alert.setVolume(0)和一些EventInjector键,但这不起作用.
那么如何使来电静音?
解决方法
我对你的问题感到困惑,决定接受挑战.我试过不同的东西,包括
>播放“静音”音频文件,希望重叠设备的响铃或占用媒体播放器
>通过UiApplication.getUiApplication()黑客手机屏幕.getActiveScreen()
>注入键盘事件
最后,注入VOLUME UP键(VOLUME DOWN键也能正常工作)对我有用,并使设备在来电时静音.这种方法的缺点是有时设备在静音之前会振铃几分之一秒.
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,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(); } }
以下也有效(使用以下代码替换callIncoming()方法中的Muter线程).
UiApplication.getUiApplication().invokeLater(new Runnable() { public void run() { EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN,0)); } });