Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
myraddin
Posts: 409
Registered: ‎09-12-2008
My Device: 9000 9810

Turn off ringer ?

Is there a way to set the ringer's volume to zero during a program execution?

 

Something similar to 'bedside mode', but done programaticaly?

 

I don't want the user to select the silent profile, but instead just mute the ringer for a while.

 

 

Thanks all.

 

 



"Listen carefully, I shall say this only once"
Please use plain text.
Developer
simon_hain
Posts: 16,044
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Turn off ringer ?

no, that is not possible.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
Posts: 432
Registered: ‎02-23-2009
My Device: Not Specified

Re: Turn off ringer ?

You can create an event of pressing "volume down" key using EventInjector when you recieve IncomingCall notification.
Deepesh Gupta
Please use plain text.
Developer
Posts: 432
Registered: ‎02-23-2009
My Device: Not Specified

Re: Turn off ringer ?

 If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish

 

Deepesh Gupta
Please use plain text.
Developer
myraddin
Posts: 409
Registered: ‎09-12-2008
My Device: 9000 9810

Re: Turn off ringer ?

I've tried the VOLUME_DOWN hack, and it works OK in the simulator, but on the device, the audio controller is way too fast.

So, the ringer starts and then mutes.That's not what I had in mind :smileysad:

 

Any other ideas ?



"Listen carefully, I shall say this only once"
Please use plain text.
Developer
Posts: 432
Registered: ‎02-23-2009
My Device: Not Specified

Re: Turn off ringer ?

Its working fine here on handheld also. When i injetc the event of of VOLUME_DOWN key then the call mutes. Check Your code again otherwise send your piece of code to me.

 

 


If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish

 

 

Deepesh Gupta
Please use plain text.
Developer
simon_hain
Posts: 16,044
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Turn off ringer ?

i just stumbled upon some methods yesterday. don't have any time to test them, would be nice if you share your results though.

take a look at the Alert class. it features some methods that could be working:

static void setVolume(int volume)
Sets the master volume.

static void stopAudio()
Cancels an audio alert in progress.

static void mute(boolean newMuteState)
Toggles the device between mute (volume 0) and loud state, and persists the current volume level.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
myraddin
Posts: 409
Registered: ‎09-12-2008
My Device: 9000 9810

Re: Turn off ringer ?

I've tried with

 

Alert.mute(true); // similar to: Alert.setVolume(0);

 

The Alert volume does get reduced to 0, but the ringer is still on.

 

I've injected the end key (inside callIncoming(int arg)) like this:

 

Application.getApplication().invokeLater(new Runnable() { public void run() { // injecting Mute, Volume UP/DOWN turns off the ringer: // not working on the device :( EventInjector.KeyCodeEvent ev = new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN, ((char) Keypad.KEY_VOLUME_DOWN), KeypadListener.STATUS_ALT, 500); EventInjector.invokeEvent(ev); } }/*, 100, false*/);

 

I have to use invokeLater because if I don't, the incomming call screen is not yet displayed at the time the injection occures, thus disabling the effect. This way, I wait until the event thread finishes and the incoming call screen is displayed.

 

In the simulator for 8110 this works fine. But on the device (8110) I hear the first ring, and then it is muted - a bit too late for me.

 

In most of the cases I know that there is an incoming call coming so if there is such an option, I would mute the ringer even before the callIncoming() gets called.

 

But how ?

 

Thank you all for your efforts.

 

 



"Listen carefully, I shall say this only once"
Please use plain text.
Developer
Posts: 432
Registered: ‎02-23-2009
My Device: Not Specified

Re: Turn off ringer ?

When you inject VOLUME_DOWN using eventinjector in callIcoming() method, there was no icoming call screen shown.

Is it like that? because it just need to turn the volume off. we are not doing anything to hide the incoming call screen.

 

Check again there must be incoming call screen.

 


If your problem was get solved then please mark the thread as "Accepted solution".
Press the kudos button to thank the user who helped you.

 

 

 

Deepesh Gupta
Please use plain text.
Developer
myraddin
Posts: 409
Registered: ‎09-12-2008
My Device: 9000 9810

Re: Turn off ringer ?

Let's rewind a little bit.

 

If you put a breakpoint in the first line of the callIncoming() handler, you can observe (in the simulator is the same thing as on the device) that the incoming call screen has not yet appeared. And that is ok. It will not appear until this thread finishes current handling (until you leave the callIncoming method).

The incoming call screen drawing is in the same thread but scheduled after the callIncoming() execution.

 

Thus, if you don't use invokeLater inside callIncoming() it will be executed prior incoming screen appearing and it will not 'catch' the injected key. The VOLUME_DOWN will be sent to home screen (if you were there at the time when the call arrived).

 

The answer to your question:

No. The incoming call screen does appear, but the ringer appears to start even before that happens.

This is how I envision the thread schedule:

1) callIncoming()   - inject the VOLUME_DOWN using invokeLater

2) audio: ring()

3) draw incoming call screen

4) execute job waiting ( VOLUME_DOWN )

 

(I cannot know for sure which comes first 2 or 3, but it doesn't matter as we cannot control that)

 

In the simulator ('unlimited' CPU power) 2, 3 and 4 are done very fast so the incoming call screen catches the VOLUME_DOWN, interprets the "user's"desire to mute the ringer and sends stopRinger() even before it started ringing.

 

But on the device itself, there is a different story. As I understand, the 2) gets handled very quickly. Then comes 3). The screen is now drawn, and our injection follows. But, to my sorrow - a bit too late. 

 

So this scheme if injecting VOLUME_DOWN (or any other key) during callIncoming handler execution is a bit risky.

And you say it always work for you?

 

Can you post the code? Maybe I am missing something.

 



"Listen carefully, I shall say this only once"
Please use plain text.