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
Contributor
netrevolver
Posts: 31
Registered: ‎03-15-2013
My Device: 9320
Accepted Solution

Blackberry Notification Bar: How to replace Message Preview Window

[ Edited ]

Hi I'm trying to make my first blackberry app using eclipse, the main idea of the app is only to show current location based on internal GPS LatLong << skip this part.

now the question is I've been looking for almost two weeks about how to replace "Message Preview" window that appear if custom message is clicked

 

Here's my code

 

Class DemoMessage

 

public final class DemoMessage implements ApplicationMessage
{
static final int DEMO_MESSAGE_TYPE = 0x01;

private String _sender;
private String _subject;
private String _message;
private long _receivedTime;
private boolean _isNew;
private boolean _deleted;
private String _replyMessage;
private long _replyTime;
private EncodedImage _previewPicture;

public DemoMessage()
{
    _isNew = true;
}

DemoMessage(String sender, String subject, String message, long receivedTime)
{
    _sender = sender;
    _subject = subject;
    _message = message;
    _receivedTime = receivedTime;
    _isNew = true;
}

void reply(String message)
{
    markRead();
    _replyMessage = message;
    _replyTime = System.currentTimeMillis();
}

void messageDeleted()
{
    _isNew = false;
    _deleted = true;
}

void markAsNew()
{
    _isNew = true;
    _replyMessage = null;
}

void markRead()
{
    _isNew = false;
}

boolean isNew()
{
    return _isNew;
}

boolean hasReplied()
{
    return _replyMessage != null;
}

void setSender(String sender)
{
    _sender = sender;
}

void setSubject(String subject)
{
    _subject = subject;
}

void setReceivedTime(long receivedTime)
{
    _receivedTime = receivedTime;
}

void setMessage(String message)
{
    _message = message;
}

String getMessage()
{
    return _message;
}

void setPreviewPicture(EncodedImage image)
{
_previewPicture = image;
}

public String getContact()
{
return _sender;
}

public int getStatus()
{
    if(_isNew)
    {
        return MyApp.STATUS_NEW;
    }

    if(_deleted)
    {
        return MyApp.STATUS_DELETED;
    }

    if(_replyMessage != null)
    {
        return MyApp.STATUS_REPLIED;
    }

    return MyApp.STATUS_OPENED;
}

public String getSubject()
{
    if(_replyMessage != null)
    {
        return "Re: " + _subject;
    }
    else
    {
        return _subject;
    }
}

public long getTimestamp()
{
    return _receivedTime;
}

public int getType()
{
    return DEMO_MESSAGE_TYPE;
}

public String getPreviewText()
{
    if(_message == null)
    {
        return null;
    }

    StringBuffer buffer = new StringBuffer(_message);

    if(_replyMessage != null)
    {
        buffer.append(". You replied on ").append(new Date(_replyTime)).append(": ").append(_replyMessage);
    }

    return buffer.length() > 100 ? buffer.toString().substring(0, 100) + " ..." : buffer.toString();
}

public Object getCookie(int cookieId)
{
    return null;
}

public Object getPreviewPicture()
{
    return _previewPicture;
}
}

Class DemoMessageScreen

 

public final class DemoMessageScreen extends MainScreen
{
public DemoMessageScreen()
{       
    setTitle("Title");
    ApplicationMessageFolder folder = null;
    ApplicationFolderIntegrationConfig config = new ApplicationFolderIntegrationConfig(true, true, ApplicationDescriptor.currentApplicationDescriptor());

    if(ApplicationMessageFolderRegistry.getInstance().getApplicationFolder(0x33c7ce29883abe5fL)==null)
    {
         folder = ApplicationMessageFolderRegistry.getInstance().registerFolder(0x33c7ce29883abe5fL, "Test Folder", new ReadableListImpl(),config );
    }
    else
    {
         folder = ApplicationMessageFolderRegistry.getInstance().getApplicationFolder(0x33c7ce29883abe5fL);
    }

    ReadableListImpl mylist= new ReadableListImpl();
    DemoMessage msg = new DemoMessage("me@here.com", "Pizza Toppings","What would you like on your pizza?", System.currentTimeMillis());
    mylist.addMessage(msg);

    folder.fireElementAdded(msg,true);
    System.out.println("nr of messages"+folder.hasNewMessages());

    EncodedImage image = EncodedImage.getEncodedImageResource("indicatorOn.png" );
    ApplicationIcon icon = new ApplicationIcon( image );
    ApplicationIndicatorRegistry reg = ApplicationIndicatorRegistry.getInstance();
    ApplicationIndicator indicator = reg.register(icon, false, true);
    indicator.setNotificationState(true);

    ApplicationIndicator appIndicator = reg.getApplicationIndicator();
    appIndicator.setIcon(icon);
    appIndicator.setValue(appIndicator.getValue() + 1);
    //appIndicator.setNotificationState(true);
    appIndicator.setVisible(true);
}

public boolean onClose()
{
    close();
    return true;
}

static class ReadableListImpl implements ReadableList
{
    private Vector messages;

    ReadableListImpl()
    {
        messages = new Vector();
    }

    public Object getAt(int index)
    {
        return messages.elementAt(index);
    }

    public int getAt(int index, int count, Object[] elements, int destIndex)
    {
        return 0;
    }

    public int getIndex(Object element)
    {
        return messages.indexOf(element);
    }

    public int size()
    {
        return messages.size();
    }

   void addMessage(DemoMessage message)
    {
        messages.addElement(message);
    }

    void removeMessage(DemoMessage message)
    {
        messages.removeElement(message);
    }
}
}

and Class MyApp

 

public class MyApp extends UiApplication
{
static final int FLAG_REPLIED = 1 << 16;
static final int FLAG_DELETED = 1 << 17;
static final int BASE_STATUS = ApplicationMessage.Status.INCOMING;
static final int STATUS_NEW = BASE_STATUS | ApplicationMessage.Status.UNOPENED;
static final int STATUS_OPENED = BASE_STATUS | ApplicationMessage.Status.OPENED;
static final int STATUS_REPLIED = BASE_STATUS | ApplicationMessage.Status.OPENED | FLAG_REPLIED;
static final int STATUS_DELETED = BASE_STATUS | FLAG_DELETED;

public static void main(String[] args)
{
    MyApp theApp = new MyApp();      
    theApp.enterEventDispatcher();
}

public MyApp()
{   
        pushScreen(new DemoMessageScreen());
}
}

the codes are fine, i can see the notification at homescreen and message folder, but it calls "Message Preview" window if clicked, i don't know how to register a click handler to launch my application from notification message bar and message folder, how to do that? thanks in advance


 

Developer
crispyoz
Posts: 223
Registered: ‎10-01-2011
My Device: Bold 9900

Re: Blackberry Notification Bar: How to replace Message Preview Window

[ Edited ]

I don't have time to go through all your code right now. But I can tell you to check if getStatus()  is returning the expected message state, if it isn't then you will see the standard message preview instead of firing up your application.

 

 

Have you registered a call back listener?

 

ApplicationMessageFolderRegistry reg = ApplicationMessageFolderRegistry.getInstance();

// Some context menu items don't need a GUI (e.g. an item for deleting a message) and will be run in the current daemon application.
ApplicationDescriptor appDescr = ApplicationDescriptor.currentApplicationDescriptor();
// Callback to run application when user clicks on an item
ApplicationDescriptor uiCallbackDescr = new ApplicationDescriptor(appDescr, Constants.APPLICATION_NAME, new String[] {"gui"});

Contributor
netrevolver
Posts: 31
Registered: ‎03-15-2013
My Device: 9320

Re: Blackberry Notification Bar: How to replace Message Preview Window

[ Edited ]

thanks, but no, the getStatus is always return _isNew = true, i have to change it to OPENED or _isNew = false manually..

 

ok i will try to add call back listener, be right back :smileyhappy:

 

i have declared ApplicationMessageFolderRegistry, ApplicationDescriptor appDescr and ApplicationDescriptor uiCallbackDescr in public DemoMessageScreen class but uiCallbackDescr give me an error at Constants.APPLICATION_NAME "cannot be resolved to a variable"

Developer
crispyoz
Posts: 223
Registered: ‎10-01-2011
My Device: Bold 9900

Re: Blackberry Notification Bar: How to replace Message Preview Window

In my code sample   Constants.APPLICATION_NAME  is just the name of the application I have defined in a my own code.  Just replace it with the name of your application with proper case sensitivity.

 

The listener is what triggers your app to be used as the viewer, basically it is listening for a click on an item that matches the application descripter,  and telling it to run the application named "MyAppName"  passing it the parameter  "gui": 

 

ApplicationDescriptor uiCallbackDescr = new ApplicationDescriptor(appDescr, "MyAppName", new String[] {"gui"});

 

 

Contributor
netrevolver
Posts: 31
Registered: ‎03-15-2013
My Device: 9320

Re: Blackberry Notification Bar: How to replace Message Preview Window

[ Edited ]

ok thanks for the explanation, now you know i'm not a java programmer :smileyhappy: , i will search code sample for that, be right back

 

i found the following code and added to DemoMessageScreen class

 

        if(ApplicationMessageFolderRegistry.getInstance().getApplicationFolder(0x33c7ce29883abe5fL)==null)
        {
             folder = ApplicationMessageFolderRegistry.getInstance().registerFolder(0x33c7ce29883abe5fL, "Test Folder", new ReadableListImpl(),config );
        }
        else
        {
             folder = ApplicationMessageFolderRegistry.getInstance().getApplicationFolder(0x33c7ce29883abe5fL);
        }
 
        try
        {
            ApplicationDescriptor daemonDescr = ApplicationDescriptor.currentApplicationDescriptor();
            ApplicationDescriptor mainDescr = new ApplicationDescriptor(daemonDescr, "MyAppName", new String[] {"gui"});
            ApplicationFolderIntegrationConfig inboxIntegration = new ApplicationFolderIntegrationConfig(true, true, mainDescr);
            folder = ApplicationMessageFolderRegistry.getInstance().registerFolder(0x33c7ce29883abe5fL, "Test Folder", new ReadableListImpl(),inboxIntegration);
        }
        catch (IllegalArgumentException e)
        {
            e.printStackTrace();
        }
        catch (NullPointerException e)
        {
            e.printStackTrace();
        }
        
        DemoMessage msg = new DemoMessage("me@here.com", "Pizza Toppings","What would you like on your pizza?", System.currentTimeMillis());
 
        mylist.addMessage(msg);
 
        folder.fireElementAdded(msg,true);

is that what you meant?

i tried to debug as BB app and still get the message preview window...

Regular Contributor
rakeshmjiyani
Posts: 66
Registered: ‎08-28-2010
My Device: 9630

Re: Blackberry Notification Bar: How to replace Message Preview Window

I am also facing the same problem.

 

but i have one more question as below.

 

i am able to get the notification icon as well as message in the message folder.

 

But when i delete the message my notification icon is not removed...

 

can someone help me with code that how i could remove the notification icon once message is deleted from folder.

 

Please don't give solution that i need to restart the blackberry phone.  but i want delete the notification icon

through application.

 

Any help with code are appreciated.

 

Thank,

 

Contributor
netrevolver
Posts: 31
Registered: ‎03-15-2013
My Device: 9320

Re: Blackberry Notification Bar: How to replace Message Preview Window

[ Edited ]

@rakeshmjiyani i think you need fireElementRemoved(deletedMessage); and reg.unregister(); to delete notification, but my code is already overwritten, you can test it inside public boolean onClose(), we have the same problem, this can be solved if we know how to make a custom message preview and put remove notification code on it.

Regular Contributor
rakeshmjiyani
Posts: 66
Registered: ‎08-28-2010
My Device: 9630

Re: Blackberry Notification Bar: How to replace Message Preview Window

its really tough to work with blackberry.

 

 

i am having the same problem but its clueless to found the solution.

 

i am able to have the notification but dont know how to remove the notification. can u provoid full code

that can easily help me to add or remove notification using statust bar.

Contributor
netrevolver
Posts: 31
Registered: ‎03-15-2013
My Device: 9320

Re: Blackberry Notification Bar: How to replace Message Preview Window

that is the problem i dont have the code anymore, i collect them from many sources and now it is overwritten with different code, but i remember to use fireElementRemoved(deletedMessage); and reg.unregister(); to remove message from notification bar, i will search that code if i find solution how to make a custom message preview screen or to call a custom screen when i click any message in notification bar or message folder..

Regular Contributor
rakeshmjiyani
Posts: 66
Registered: ‎08-28-2010
My Device: 9630

Re: Blackberry Notification Bar: How to replace Message Preview Window

ok

 

can u do one thing...if u get that code how to remove notification icon...would you post here later full code ...it would

be greate help from you.

 

as i am currently not able to remove the notification icon once message is deleted ...i am going to plan

vibrate alert and only message....so if message is deleted i dont have any tension for vibrate alret..

as it will play sound and will be stop..no need to worry about removing alert...

 

regards,