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
New Developer
osilva
Posts: 26
Registered: ‎09-24-2008
My Device: Not Specified
Accepted Solution

Alert from a background application

[ Edited ]

Hello

 

I have a Backgorund application that is asking a number to a server, when the server returns '0' nothing happens and when it returns ´1´ an alert appear (based on How_To_-_Alert_a_user_from_a_Background_application).

 

a couple of questions:

 

1. the application appears in the task switch, i think due to the "extend UiAplication", it doesnt have any screen or form to show, only the alert, when i chose my application on the switch it appears a white screen as expected. but is there some way that just the application doesnt appear there?

 

2. it must be an easy one. how can i add a sound or  vibration action to the Alert?

 

Thank You! 

Message Edited by osilva on 10-15-2008 11:39 AM
Message Edited by osilva on 10-15-2008 05:13 PM
Please use plain text.
Developer
peter_strange
Posts: 19,604
Registered: ‎07-14-2008
My Device: Not Specified

Re: Alert from a background application

1. If you don't want your application to appear on the Task Switch List, you must extend Application not UiApplication.  However, if you are opening a connection to a Server, it may be that the Blackberry OS requires you to extend UiApplication, because it uses your UiApplication to display the pop-up screen that requests authorization.  Certainly this used to the be the case, not sure it is still a requirement for the later OS Levels.

 

2.  See Alert, in the API (net.rim.device.api.system.Alert)   Though I think these days, the more common way to do this sort of thing is to use the Notification API, so the user can set the type of Alert associated with your Application.  See the NotificationsDemo sample supplied with the JDE for further information. 

 

 

Please use plain text.
New Developer
osilva
Posts: 26
Registered: ‎09-24-2008
My Device: Not Specified

Re: Alert from a background application

[ Edited ]

Ok.

 

1. I extend only "Application" not "UI.." and it dissapeared from the task switch list,

 

2. I setted all the alarms i could, Sound, Led, buzzer and Vibrate. im not sure if the "buzzer" (is it Vibration + sound?)  action is bleeding the sound, i listen the sound very soft. if i dont have it close to my hear i cant listen it. 

 

3. i would like to stop the LED blinking state when the user press the "ok" button of the notifyUser() function, is this possible?

Message Edited by osilva on 10-15-2008 04:19 PM
Please use plain text.
New Developer
osilva
Posts: 26
Registered: ‎09-24-2008
My Device: Not Specified

Re: Alert from a background application

i have this:

 

if (flag == 1){

                               short[] tune = new short[2];

                               tune[0]= 500;

                               tune[1]= 2000;                               

                               int volume = 100;

                               LED.setColorConfiguration(500, 250, 0x0000FF00);

                               LED.setState(LED.STATE_BLINKING);

                                Alert.startAudio(tune, volume);

                               // Alert.startBuzzer(tune, volume);

                                Alert.startVibrate(2000);

                                notifyUser("You have received a message");

                                sleep(2000);

 

and...

 

 private void notifyUser(String data){

        UiEngine ui = Ui.getUiEngine();

        Screen screen = new Dialog(Dialog.D_OK, data, Dialog.OK,Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION),Manager.VERTICAL_SCROLL);

        ui.queueStatus(screen, 1, true);

        //Alert.stopBuzzer();

        LED.setState(LED.STATE_OFF);

        Alert.stopAudio();

        Alert.stopVibrate();

    } 

 

 

The sound and the vibration last very few time. the same than the Blinking state of the led,  it seems like if the notifyUser interrupt the alarms.  

Please use plain text.
Developer
peter_strange
Posts: 19,604
Registered: ‎07-14-2008
My Device: Not Specified

Re: Alert from a background application

What you see (the very short sound etc) makes sense.  The queueStatus() is not blocking.  So as soon as you have queued this screen for display, the following code is executed and your code turns everything off.

 

I suspect you have these choices

1) Associate a DialogClosedListener with your Dialog, and turn off your notifications in there

2) Start another Thread that sleeps for whatever period you want and then turns the things off

3) Put the turn off code in your mainline, i.e. after the sleep(2000);

 

I would probably do (1), though it is also probably the most work.

 

I would also recommend that you change the priority of your screen from 1 to a larger number.  I've had problems with priority 1 notifications overlaying System Dialogs, which I don't think you want.  I tend to use 99, though I've no good reason for doing so.

Please use plain text.
New Developer
osilva
Posts: 26
Registered: ‎09-24-2008
My Device: Not Specified

Re: Alert from a background application

i did this:

 

LED.setColorConfiguration(500, 250, 0x0000FF00);

                               LED.setState(LED.STATE_BLINKING);

                                Alert.startAudio(tune, volume);

                               // Alert.startBuzzer(tune, volume);

                                Alert.startVibrate(2000);

                                sleep(3*1000);

                                notifyUser("");

 

and the alarms remain during the sleep time, 

 

i will try the numer 1 later..

 

Thanks a lot 

Please use plain text.
New Developer
dal211
Posts: 3
Registered: ‎01-23-2009
My Device: Not Specified

Re: Alert from a background application

Re 1. "the application appears in the task switch"

You can prevent a UiApplication from appearing in the task switch list by overriding the protected bool acceptsForeground() method so that it returns false. This is helpful if your UiApplication has an alternate entry point that must run in the background all the time for notifications and such. Just remember to make sure it returns true  when your application is running from the UI entry point and you'll need to call requestForeground() when the user invokes the app.

 

Please use plain text.
New Developer
javiergv
Posts: 50
Registered: ‎03-18-2009
My Device: 8530

Re: Re: Alert from a background application

Good point of Dal211 because I had a menuitem and the registration doubled when I make an exit and for that reason could not get out, the problem is leaving the application running and displayed in the taskbar switch list menu. with the override acceptsforeground return false this icon dissapear but the uiapplication no runs. Defined a boolean when the application was running and when I was in the entry point and is ready. Thanks a lot. Sorry for my bad english.
// Code for getting Thanks
if( iWasHelpful && solvedYourProblem ) {
Thanks++;
solution = true;
}
Please use plain text.