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
Syamphu
Posts: 33
Registered: ‎10-29-2010
My Device: Not Specified
Accepted Solution

Cant call ESC key twice from key event

Hello this is my second post here...

lately im trying to call the camera application via:

 

            UiApplication.getUiApplication().addFileSystemJournalListener(new fileJournal());
            Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA, new CameraArguments());

 

and when the user take a picture then the application will catch the file location and close the camera application. but when i trying to close the camera application using:

 

            EventInjector.KeyEvent inject = new EventInjector.KeyEvent(EventInjector.KeyEvent.KEY_DOWN, Characters.ESCAPE, 0);
            inject.post();

            inject.post();

 

it just call the inject.post() once and skip the bottom one (when i tried it on simulator its works well but when i tried it on gemini 8520 its not work just like the simulator). i put the inject.post() at the end of my FileSystemJournalListener class.

 

is there anyone that can help me please,thanks

Please use plain text.
Developer
Syamphu
Posts: 33
Registered: ‎10-29-2010
My Device: Not Specified

Re: Cant call ESC key twice from key event

if this cant be done then is there a way to add camera control to the camera example?like to zoom in and zoom out?

Please use plain text.
Developer
jprofitt
Posts: 604
Registered: ‎12-27-2010
My Device: Not Specified

Re: Cant call ESC key twice from key event

I believe you need a KEY_UP as well.

Please use plain text.
Developer
Syamphu
Posts: 33
Registered: ‎10-29-2010
My Device: Not Specified

Re: Cant call ESC key twice from key event

hmmmm i need to inject key up as well?

ic ic let me try it...

but when i debug it on device,the code never called... the last inject.post never called... its always skip it...

Please use plain text.
Developer
Syamphu
Posts: 33
Registered: ‎10-29-2010
My Device: Not Specified

Re: Cant call ESC key twice from key event

looks like the problem is on the permission application.

on the permission option inside the settings i change the interaction permission to allow (before it was custom) and then the code just works fine.

 

now what im going to ask is,how to ask interaction permission?

i use PERMISSION_INPUT_SIMULATION but its not works

Please use plain text.
Developer
jprofitt
Posts: 604
Registered: ‎12-27-2010
My Device: Not Specified

Re: Cant call ESC key twice from key event

I've had to use it to simulate copy and paste before, he's what I did to get permission to use it:

 

ApplicationPermissionsManager apm = ApplicationPermissionsManager.getInstance();
ApplicationPermissions ap = new ApplicationPermissions();

if(apm.getPermission(ApplicationPermissions.PERMISSION_INPUT_SIMULATION) == ApplicationPermissions.VALUE_DENY) {
	 ap.addPermission(ApplicationPermissions.PERMISSION_INPUT_SIMULATION);
	ReasonProvider rp = new ReasonProvider() {
		public String getMessage(int permissionID) {
			if(permissionID == ApplicationPermissions.PERMISSION_INPUT_SIMULATION) {
				return "<an explanation of why you need the permission>";
			}
			
			return null;
		}
	};
	try{
		apm.addReasonProvider(ApplicationDescriptor.currentApplicationDescriptor(), rp);
		
	}
	catch(IllegalArgumentException e) {
		
	}
	
	apm.invokePermissionsRequest(ap);
}

 

 

Please use plain text.
Developer
StevenKader
Posts: 644
Registered: ‎02-03-2010
My Device: Z10 LE

Re: Cant call ESC key twice from key event

If the permissions are set you may need to play with the timing on a real device.  I would change it as follows and try it .

 

            EventInjector.KeyEvent inject = new EventInjector.KeyEvent(EventInjector.KeyEvent.KEY_DOWN, Characters.ESCAPE, 100);
            inject.post();

           try {

              Thread.sleep (500) ;

            } catch (Exception e) {}

            inject.post();


Steven Kader at JaredCo
   Follow me on Twitter    |     Mipixi.com :  Web App for Photo Sharing
Please use plain text.