BlackBerry - KeyPress Event Simulation

I have a BlackBerry application that needs to be removed from the camera and sent to the server. To do this, I call the application of my own camera and listen to the file system. As soon as the image is captured and saved as a new jpeg file, I get a notification, resume front-end management and do my business. The problem starts the first time this cycle is completed, because now that I have decided to call the camera application again, it is already open, and now the user sees a thumbnail of the last shot that was taken, and a few buttons that allow him to manipulate / control it. Naturally, I want the user to see a preview of what the camera β€œsees” before he clicks another photo, as he did before.

I thought of various ways to solve this problem, including how to kill the camera application every time (I understand that it is impossible to do it programmatically?), Sending an CameraArgumentsapplication (which seems useless) when calling, and now I was thinking the solution may Be like simply generating a β€œ Back ” key event before switching back to my application, which theoretically rejects the annoying editing screen. Could this really be done? and if there is no other possible solution that you can think of?

+3
source share
1 answer

Type of hacking ...

  • launch camera app
  • TimerTask , Camera, ( )
  • , ( ) ESC, .

:

class Scr extends MainScreen {
    boolean killCameraApp = false;
    final String mCameraModuleName = "net_rim_bb_camera";
    final CameraArguments args = new CameraArguments();

    public Scr() {
        super();

        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {
            public void run() {
                if (isCameraRunning() && killCameraApp) {
                    getApplication().invokeAndWait(callCamera);
                    getApplication().invokeAndWait(killCamera);
                }
            }
        }, 0, 100);
    }

    Runnable callCamera = new Runnable() {
        public void run() {
            callCamera();
        }

    };

    Runnable killCamera = new Runnable() {
        public void run() {
            injectKey(Characters.ESCAPE);
            killCameraApp = false;
        }
    };

    private boolean isCameraRunning() {
        boolean result = false;
        ApplicationManager appMan = 
                ApplicationManager.getApplicationManager();
        ApplicationDescriptor[] appDes = appMan.getVisibleApplications();
        for (int i = 0; i < appDes.length; i++) {
            result = mCameraModuleName.equalsIgnoreCase(appDes[i]
                    .getModuleName());
            if (result)
                break;
        }
        return result;
    }

    private void callCamera() {
        Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA, 
                new CameraArguments());
    }

    private void injectKey(char key) {
        KeyEvent inject = new KeyEvent(KeyEvent.KEY_DOWN, key, 0);
        inject.post();
    }

    protected void makeMenu(Menu menu, int instance) {
        menu.add(new MenuItem("start camera", 0, 0) {
            public void run() {
                callCamera();
                killCameraApp = false;
            }
        });
        menu.add(new MenuItem("kill app", 0, 0) {
            public void run() {
                killCameraApp = true;
            }
        });
        super.makeMenu(menu, instance);
    }
}

EDIT: :
= > = > = > [ ] = > = > = >

+4

Source: https://habr.com/ru/post/1715405/


All Articles