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
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Inserting characters into another application

Apologies, my code was incorrect, you should have used UiApplication.getUiApplication().

 

I must admit I have, in the past, used

UiApplication.getUiApplication().getActiveScreen()

in an ApplicationMenuItem that I added to the System, so that it was added to all RIM application screens.  This code did, from memory, get access to the screen being displayed, which presumably is the screen that the paste is going into.  So I am very surprised this does not work for you. 

 

 

Contributor
Posts: 11
Registered: ‎12-14-2010
My Device: Tour 9630
My Carrier: Sprint

Re: Inserting characters into another application

It's strange, isn't it?  I stripped down the whole app to a simple hello world app consisting of a MainScreen and the main method that pushes the mainscreen.  I can get the active screen using:

 

UiApplication.getUiApplication().getActiveScreen()

 

Yet, the screen below:  null

 

I don't understand.  There is even an example of how to do this in these forums by the Blackberry gurus M. Sohm and company.  I can get my screen (and this is only if I push it non-globally) and that's it.

 

I agree with you, the get screen below and getLeafWithFocus will be the way to go.  Also,  if I can get access to the screen below, I can it's own menu to paste the character and skip eventinjection all together.  (not a big fan of it either--too unpredictable!)

 

I'm going to keep trying.   Hopefully I can find out what I'm doing wrong that's causing me to lose access.

 

Thanks again.

Contributor
Posts: 11
Registered: ‎12-14-2010
My Device: Tour 9630
My Carrier: Sprint

Re: Inserting characters into another application

Hi peter,

 

I've been doing some tesing.  In OS 5.0, I cannot seem to get the screen below my app's screen.  It simply returns null.  Here the code I used to verify this:

 

 

class TestApp extends UiApplication {
	public TestApp() {
		pushScreen(new Screen());
	}
	public static void main(String[] args) {
		TestApp app = new TestApp();
		app.enterEventDispatcher();
	}
}

class Screen extends MainScreen {
	private static LabelField status = new LabelField("Status");
	private ButtonField button1;
	private ButtonField button2;
	
	Screen() {
		button1 = new ButtonField("Show activeScreen", ButtonField.CONSUME_CLICK) {
			protected boolean navigationClick( int status, int time ) {
				Screen scr;
				if ( (scr=(Screen) UiApplication.getUiApplication().getActiveScreen()) != null) {
					Screen.status.setText(scr.toString());
					invalidate();
				}	
				else {
					Screen.status.setText("null");
					invalidate();
				}
				return true;
			}
		};
		button2 = new ButtonField("Show activeScreenBelow", ButtonField.CONSUME_CLICK) {
			protected boolean navigationClick( int status, int time ) {
				Screen scr;
				if ( (scr=(Screen) UiApplication.getUiApplication().getActiveScreen().getScreenBelow()) != null) {
					Screen.status.setText(scr.toString());
					invalidate();
				}	
				else {
					Screen.status.setText("null");
					invalidate();
				}
				return true;
			}
		};		
		setTitle(new LabelField("TestApp"));
		add(button1);
		add(button2);		
		add(status);
	}
}

 

If I stack screens within my app, I can get the stack.  It seems that UiApplication will only allow you access to your own applications screen stack.  This brings me back to my original problem, how can I detect whether another apps field with focus is editable?

 

Anyone have any ideas how to approach this?  Or is there a way to get the full (system) stack of screens?

 

Developer
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: Inserting characters into another application

[ Edited ]

Each application has its own screen stack. You cannot access screens from another application by using getScreenBelow() inside your own application. Returning null from your bottom-most screen is expected.

 

The only way you are going to get the screen of a third party app like this is to use the menu item and get the active screen once the menu item is run (stop thinking in terms of screen-below). In my experience this should work. If it is not working for you, try other applications with the same menu item, perhaps the one you are trying is protected by RIM from this.

Contributor
Posts: 11
Registered: ‎12-14-2010
My Device: Tour 9630
My Carrier: Sprint

Re: Inserting characters into another application

[ Edited ]

It looks like the screen below method is definately NOT the way to go.  I've proven that with the simple TestApp I've posted above.

 

mreed:  How do you propose I get access through the menuitem?  If I use the context object passed to the run method, I receive a null reference for some of the apps I need access to.  Is there another way of doing this?

 

Thanks

Developer
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: Inserting characters into another application

The context object passed in is something different entirely. The menu item should be executed on the third-party app process. What i was saying was that calling UiApplication.getUiApplication() should get you a reference to the third-party application. If it is not, and you are testing this on a RIM application, then you should try it on other applications since some RIM apps may be specifically protected against things like this. For instance some RIM apps block out key injection, so they may block out other things as well.

Contributor
Posts: 11
Registered: ‎12-14-2010
My Device: Tour 9630
My Carrier: Sprint

Re: Inserting characters into another application

mreed:

 

In therun method of my ApplicationMenuItem:

 

public Object run(Object context) {  
            System.out.println("Current ActiveScreen:  " + UiApplication.getUiApplication().getActiveScreen());
            
            UiApplication.getUiApplication().pushGlobalScreen(thePopup, 1, UiEngine.GLOBAL_QUEUE);
            return null;
        }  

 

 

System out is: null

 

Any ideas?

 

 

Developer
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: Inserting characters into another application

What app are you running this menu item from? what other apps have you tried running it from?

Contributor
Posts: 11
Registered: ‎12-14-2010
My Device: Tour 9630
My Carrier: Sprint

Re: Inserting characters into another application

I tried running it from the TestApp I posted earier, BBM, calendar, tasks, email, memopad, text, etc.  Basically any of the text based apps. Even from the home screen.  All return null.

 

If I can only get an Ui instance of the app that runs the menuitem, I would be set.

 

I know this is possible because I've seen apps that insert text into other apps.  And those apps will issue a dialog warning the user is NOT in an editable field. 

 

My app functions perfect except for this one small detail.  I need this to be robust before I put this into production.  It just seems like I'm missing something really simple. (Spent more time getting this to work than I did writing this thing---frustrating!)

Highlighted
Developer
Posts: 204
Registered: ‎07-09-2009
My Device: Not Specified

Re: Inserting characters into another application

When the target app is all that's on the display (i.e. BBM), when the user presses the Menu key, your ApplicationMenuItem.toString() is called 3 times.  The first time, the context is useless, just return the string.  The second time, you are in the target app's context and can get everything, the UiApplication, UiEngine, menu, screen stack, field heirarchy, etc.  Same with the 3rd time, but you don't need that.  The top screen will be the menu's PopupScreen at that moment, with the app's current screen below.

 

So, you can get what you need before the item is actually selected, in case for some strange reason you can't get the information in the item's run().