BlackBerry - 模拟KeyPress事件 [英] BlackBerry - Simulate a KeyPress event

查看:225
本文介绍了BlackBerry - 模拟KeyPress事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个BlackBerry应用程序需要从相机拍摄照片并将其发送到服务器。为了做到这一点,我调用本机相机应用程序,并侦听文件系统。一旦图像被捕获并保存为一个新的jpeg文件,我得到通知,恢复前台控制和我的业务。该问题在第一次完成此周期后开始,因为现在当我决定再次调用相机应用程序时,它已经打开,现在用户正在看到最后拍摄的照片的缩略图和允许他操作的几个按钮/管理它。自然我想让用户看到的是相机在拍照之前拍摄照片的预览,就像他以前一样。

I have a BlackBerry application that needs to take pictures from the camera and send them to a server. In order to do this i invoke the native camera application and listen to the filesystem. Once an image is captured and saved as a new jpeg file i get notified, resume foreground control and go about my business. The problem starts occurring after the first time this cycle is completed because now when i decide to call the camera application again it is already opened, and now the user is seeing a thumbnail of the last picture that was taken and several buttons allowing him to manipulate/manage it. naturally what i want the user to see is a preview of what the camera is "seeing" before he snaps another photo as he did before.

我想到了各种方式解决这个问题,包括每次杀死相机应用程序(我理解这不能以程序方式完成?),当调用应用程序(似乎是无用的)时发送 CameraArguments 我认为一个解决方案可以简单生成返回关键事件,然后切换回我的应用程序,这将理论上解除烦人的编辑屏幕。这真的可以做吗?

I have thought of various ways to solve this including killing the camera app each time (I understand this cannot be done programatically?), sending CameraArguments when invoking the app (which appears to be useless), and now i was thinking a solution could be as simple generating a "Back" key event before switching back to my app which would theoretically dismiss the annoying edit screen. Could this really be done? and if not is there any other possible solution you may think of?

推荐答案

一种黑客...


  • 在CameraTask中启动Camera App

  • 检查Camera App是否启动以及是否需要关闭

  • 如果是,调用它(因此它将变为活动状态),然后按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:
选项=>高级选项=>应用程序=> [您的应用程序] =>编辑默认权限=>互动=>关键笔划注入

Don't forget to set permissions for device release:
Options => Advanced Options => Applications => [Your Application] =>Edit Default permissions =>Interactions =>key stroke Injection

这篇关于BlackBerry - 模拟KeyPress事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆