10-06-2010 10:32 AM - edited 10-06-2010 10:56 PM
Hi,
My Application is auto start, it shows the numbers of pending messages on HOMESCREEN with an ICON and NUMBER,
But it get updated properly when my application is in foreground ,
but when it goes to background,
and then some Message gets failed then it’s not updating the current ICON+ NUMBER instead of that it create a new ICON+ NUMBER,
Please Help me.
Here I am writing my code to set and reset...
public class IconBanner {
static EncodedImage image = null;
static ApplicationIcon appIcon = null;
static ApplicationIndicator appIndicator = null;
static ApplicationIndicator mAppIndicator = null;
static ApplicationIndicatorRegistry appIndicatorRegistry = null;
public IconBanner() {
}
/**
* Method to set banner image i.e. application icon on home screen of device.
* to show number of Unsent Email even if application is closed.
*/
public static void setBanner()
{
MailScreen mailScreen = new MailScreen(Application.getApplication());
FailedSendsSettings sendsSettings = new FailedSendsSettings(Application.getApplication());
try {
int tmp_numberOfMails = mailScreen.getNumberOfPendingMails ();// calclate no of pending message
System.out.println("Enter in setBanner " +tmp_numberOfMails);
if (image == null) {
if( tmp_numberOfMails > 0)
{
if (sendsSettings.autoOn()){
image = EncodedImage.getEncodedImageResource("yellowicon_h ome.png");
}
else
image = EncodedImage.getEncodedImageResource("redicon_home .png");
}
else
{
image = EncodedImage.getEncodedImageResource("greenicon_ho me.png");
}
}
if (appIcon == null) {
appIcon = new ApplicationIcon(image, true);
}
appIndicatorRegistry = ApplicationIndicatorRegistry.getInstance();
appIndicator = appIndicatorRegistry.register(appIcon, false, true);
mAppIndicator = appIndicatorRegistry.getApplicationIndicator();
mAppIndicator.setIcon(appIcon);
if( tmp_numberOfMails > 0)
mAppIndicator.setValue(mailScreen.getNumberOfPendi ngMails ());
} catch (Exception ex) {
}
}
/**
* Method to remove application icon from home screen.
*/
public static void resetBanner() {
MailScreen mailScreen = new MailScreen(Application.getApplication());
try{
if (appIndicatorRegistry != null || mAppIndicator != null) {
System.out.println("in reset banner %%%%%%%%%%%%%%%");
appIndicatorRegistry.unregister();
}
}catch(Exception e)
{}
appIndicatorRegistry = null;
mAppIndicator = null;
appIcon = null;
image = null;
}
public Bitmap getAppIconImage()
{
MailScreen mailScreen = new MailScreen(MailScreen.app.getApplication());
FailedSendsSettings sendsSettings = new FailedSendsSettings(Application.getApplication());
int tmp_numberOfMails = mailScreen.getNumberOfPendingMails ();
Bitmap iconBitmap = new Bitmap(32, 32);
Graphics g = new Graphics(iconBitmap);
EncodedImage image = null;
if( tmp_numberOfMails > 0 )
{
if (sendsSettings.autoOn())
{
image = EncodedImage.getEncodedImageResource("yellowicon.p ng");
}
else
{
image = EncodedImage.getEncodedImageResource("redicon.png" );
}
g.drawImage(0, 0, 32, 32, image, 0, 0, 0);
g.setFont(g.getFont().derive(Font.FONT_INPUT_TEXT, Font.SIZE_SMALL));
g.setColor(Color.BLACK);
g.drawText(""+mailScreen.getNumberOfPendingMails() , 15, 23,0);
}
else //all mail sent
{
if (sendsSettings.autoOn())
{
image = EncodedImage.getEncodedImageResource("greenicon.pn g");
}
else
{
image = EncodedImage.getEncodedImageResource("yellowicon.p ng");
}
g.drawImage(0, 0, 32, 32, image, 0, 0, 0);
}
return iconBitmap;
}
}
now i am using MessageListener to call this method code is here..
public class OutboxListener implements FolderListener, MessageListener {
Message orginalMessage;
Message [] outBoxedMessage;
Message [] temp = null;
Folder messageFolder;
Folder outBox;
Store store;
public OutboxListener() {
try {
//retrieve the default message service
store = Session.getDefaultInstance().getStore();
//add the listener
store.addFolderListener(this);
calculatePendingMails();
}catch (Exception e) {
}
}
public void messagesAdded(FolderEvent folderEvent) {
orginalMessage = folderEvent.getMessage();
orginalMessage.addMessageListener(this);
messageFolder = orginalMessage.getFolder();
}
public void messagesRemoved(FolderEvent folderEvent) {
}
public void changed(MessageEvent messageEvent) {
System.out.println("changed Status of Message of ID "+orginalMessage.getMessageId() + " "+"== "+orginalMessage.getStatus());
if((orginalMessage.getStatus() == Message.Status.TX_ERROR )
|| (orginalMessage.getStatus() == Message.Status.TX_GENERAL_FAILURE))
{
IconBanner iconBanner = new IconBanner();
MailScreen mailScreen = new MailScreen(Application.getApplication());
synchronized (net.rim.device.api.system.Application
.getEventLock()) {
calculatePendingMails();
HomeScreen.updateIcon(iconBanner.getAppIconImage() );
IconBanner.resetBanner();
IconBanner.setBanner();
}
}
}
public Message [] calculatePendingMails()
{
..................
// calclation code goes here
......................
return outBoxedMessage;
}
public int setPendingMails() {
return MailScreen.mPendingMails = outBoxedMessage.length;
}
}
Please help me ......
Thanks.
Solved! Go to Solution.
10-06-2010 10:53 PM
Hello,
If somebody help ?????
10-07-2010 02:35 PM
Will Someone reply to my question?
OR does it seems too tough to solve ?
10-09-2010 12:52 PM
WILL SOMEBODY HELP ???
10-09-2010 04:41 PM
I don't have any experience with the classes you are using so I can't really help you but most of the people who roam these forums do so either at night or on weekdays. Sorry.
I will just ask the generic questions that you will inevitably get asked at some point or another:
10-10-2010 12:58 AM
Hi Rcmaniac,
Thanks for your response,
Here are the details go below what asked for:
1. The OS I am targeting is 4.6 onwards.
2. The API I used are:
net.rim.blackberry.api.messagelist.ApplicationIcon
net.rim.blackberry.api.messagelist.ApplicationIndi
net.rim.blackberry.api.messagelist.ApplicationIndi
3. I have tried it on both Simulator - 9000 and devices 9000/9650
But same result I am getting, its not refreshing the current indicator instead of its create a new indicator when running on background
Thanks,
10-12-2010 03:10 PM
You are registering a new icon every time the method is run. Instead, you can re-use your existing registration by calling getApplicationIndicator (without first calling register).
Also note that calling Application.getApplication or UiApplication.getUiApplication may not return an instance of your application. In the case of listeners, it'll return the application firing the listener and/or the application in the foreground. This means you could be calling it from different applications, resulting in duplicate icons.
Here are some examples of creating a singleton application instance.
Create a singleton using the RuntimeStore
Allow a background listener to detect and update a GUI application