BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 11-26-2007, 10:05 AM   #1 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Change HomeScreen-Icon on an external event

Please Login to Remove!

I use an alternative entry point to register an MessageListener as well as setting a RolloverIcon using HomeScreen.updateIcon.

On arrival of a new Mail i'd like to change the icon of the application.

The first problem is that messageAdded is called by the MessageListener. I can work around that storing my Application and running InvokeLater on it.

But i am unable to change the Icon on the HomeScreen and get a IllegalArgumentException.

Here is my code, 'me' is the Application itself.

Code:
public void messageAdded(Message message) {	
	me.invokeLater(new Runnable() {
	public void run() {
	System.out.println(this.getClass());
HomeScreen.updateIcon(Bitmap.getBitmapResource("icon_test.png")); 	
}
});
}
Any ideas? Anybody tried this successfully? Won't work as it's limited to RIM?
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 11-27-2007, 08:47 AM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

Quote:
Originally Posted by simon.hain View Post
I use an alternative entry point to register an MessageListener as well as setting a RolloverIcon using HomeScreen.updateIcon.

On arrival of a new Mail i'd like to change the icon of the application.

The first problem is that messageAdded is called by the MessageListener. I can work around that storing my Application and running InvokeLater on it.

But i am unable to change the Icon on the HomeScreen and get a IllegalArgumentException.

Here is my code, 'me' is the Application itself.

Code:
public void messageAdded(Message message) {	
	me.invokeLater(new Runnable() {
	public void run() {
	System.out.println(this.getClass());
HomeScreen.updateIcon(Bitmap.getBitmapResource("icon_test.png")); 	
}
});
}
Any ideas? Anybody tried this successfully? Won't work as it's limited to RIM?
Just a thought here, and I'm not that experienced in Java so please excuse any misused terminology...

Even though you invoke getBitmapResource from a thread created by the invokeLater method, it is still running out of the app (module) that invoked messageAdded. If true this could raise two issues: 1) icon_test.png is not in the module that calls getBitmapResource (even though it is in the module that defines the code); 2) you are trying to set the icon for the module that invoked messageAdded. An indication that this is true would be the application name in the dialog box reporting the exception (if it goes uncaught). I haven't had this exact problem, but have run in to similar weirdness that makes sense when I consider that my code is actually being run as an extension to the Messaging app.

Things to try:
1) use the debugger to find out what getBitmapResource is returning;
2) use the getBitmapResource(String module, String name) version;
3) invoke your application with an argument that causes it to change the home screen icon.
Offline  
Old 11-27-2007, 11:04 AM   #3 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

that's what the 'me' is for, its a reference of my application.
the sysout gives the full application name thus i think the rest should also be executed in this context.

am i able to call my application from another application? I could move my inbox-listener to an own app then and call my mainapp with an alternative entry point, would solve the problem...
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 11-27-2007, 12:06 PM   #4 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

That all makes it more interesting, and perplexing.

In any case launching a third party app from a third party app is covered in the Knowledge base article DB-00455

Or you can invoke the current app with other arguments with something like this snippet from an alarm application I wrote:

Code:
ApplicationDescriptor me = ApplicationDescriptor.currentApplicationDescriptor();
ApplicationManager am = ApplicationManager.getApplicationManager();

String[] args = { "alarm" };
if (snooze)
{
    args[0] = "snooze";
}
        
ApplicationDescriptor ad = new ApplicationDescriptor(me,me.getName(),args);
ad.setPowerOnBehavior(ApplicationDescriptor.POWER_ON);
       
am.scheduleApplication(ad, alarmTime, false);
Offline  
Old 11-27-2007, 12:17 PM   #5 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

i'll give this a try. as changing the icon works from within the alternative entry point it should be possible to launch the application using a second alternative entry point that just changes the icon.
too bad it's too late today, i really want to find this out

how would i give arguments needed for the entry point in this call?
__________________
java developer, Devinto, hamburg/germany

Last edited by simon.hain : 11-27-2007 at 12:24 PM.
Offline  
Old 11-27-2007, 12:36 PM   #6 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

Perhaps something like:
Code:
String[] args = { "arg1", "arg2", ... "argn" };
ApplicationDescriptor me = ApplicationDescriptor.currentApplicationDescriptor();
ApplicationDescriptor ad = new ApplicationDescriptor(me,"AlternateEntryName",args);
ApplicationManager am = ApplicationManager.getApplicationManager();
am.runApplication(ad);
Another option would be to use the knowledge base code and look for the ApplicationDescriptor for your entry point. I haven't actually written code to do this so I'm guessing. The only way to set arguments seems to be in the appropriate ApplicationDescriptor constructor.
Offline  
Old 11-29-2007, 05:44 AM   #7 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot for the tips, i figured it out and it is working this way.

Here is my Code:

Code:
String[] newargs = {"homescreen"};
int modHandle = CodeModuleManager.getModuleHandle("HomeScreenIconTest");
ApplicationDescriptor[] apDes = CodeModuleManager.getApplicationDescriptors(modHandle);
ApplicationDescriptor apDes2 = new ApplicationDescriptor(apDes[0], newargs);
ApplicationManager.getApplicationManager().runApplication(apDes2);
and the main from the Class HomeScreenIconTest:

Code:
public static void main(String[] args) {
	if (args.length > 0 && args[0].equals("homescreen")) {
		HomeScreen.updateIcon(CROSS,0);
		HomeScreen.setRolloverIcon(MAN,0);
	} else {
		HomeScreenTest theApp = new HomeScreenTest();
		theApp.enterEventDispatcher();
	}
}
If my event listener (running as a system service) registers an event i can now update the icon of my main application, indicating that there is an event waiting. Maybe draw a number with graphics on the Bitmap.
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 11-29-2007, 05:48 AM   #8 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

nice, cheers for sharing simon, am sure that'll come in useful in the future.
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.