如何使来电静音

Far*_*hat 7 blackberry java-me

我正在尝试静音来电并阻止BlackBerry设备响铃.我尝试了Alert.setVolume(0)和一些EventInjector键,但这不起作用.

那么如何使来电静音?

mrv*_*nzo 6

我对你的问题感到困惑,决定接受挑战.我试过不同的东西,包括

  1. 播放"静音"音频文件,希望重叠设备的响铃或占用媒体播放器
  2. 通过黑客攻击手机屏幕 UiApplication.getUiApplication().getActiveScreen()
  3. 注入键盘事件

最后,注入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)


jpr*_*itt 3

将无法以编程方式禁用声音(找到了一些其他来源也说了同样的事情)。人们似乎想出的最好的解决方法是使用将EventInjector手机的声音配置文件更改为静音。