How to silence an incoming call

半城伤御伤魂 提交于 2019-12-07 01:40:45

问题


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?


回答1:


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));
            }
        });



回答2:


You won't be able to disable the sound programmatically (found a couple other sources that said the same thing). The best workaround people have seemed to come up with was to use the EventInjector to change the phone's sound profile to silent.




回答3:


Some Blackberry phones have a mute key. You may try the following idea:

public void callIncoming(int callId) {
    if (KeyPad.hasMuteKey()) {
        /* Inject KEY_SPEAKERPHONE event */
    }
    else {
        /* Inject KEY_VOLUME_DOWN event N times, so that you get the mute effect */
    }
}



回答4:


i am quite new to all this...but i thought i might as well put in my 2 cents worth...

i have been trying to find ways to programatically change the profile settings...

i have found that, while we cannot(yet) change the profile settings, we can change the setting that we are using( change the profile thats in use, i think)- this is something i came across searching for info-though i should give credit to alishaik786 for the code.

    public final class LoadingScreen extends MainScreen implements FieldChangeListener
    {   
        public LoadingScreen()
    {        
        createGUI();
    }

    private void createGUI() 
    {
        try 
        {           
            ApplicationManager.getApplicationManager().launch("net_rim_bb_profiles_app");
        } 
        catch (Exception e) 
        {
            //Exception
        }
    }

    public void fieldChanged(Field field, int context)
    {

    }   
}


来源:https://stackoverflow.com/questions/9431310/how-to-silence-an-incoming-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!