Far*_*hat 7 blackberry java-me
我正在尝试静音来电并阻止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, (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();
}
}
Run Code Online (Sandbox Code Playgroud)
以下也适用(用以下代码替换方法中的Muter
线程callIncoming()
).
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));
}
});
Run Code Online (Sandbox Code Playgroud)