黑莓手机 - 模拟一个关键preSS事件 [英] BlackBerry - Simulate a KeyPress event

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

问题描述

我有一个需要从相机拍照,并将它们发送到服务器的BlackBerry应用程序。为了做到这一点我调用本地摄像头应用程序并听取他们的文件系统。一旦图像被捕获并保存为一个新的JPEG文件我得到通知,恢复前景控制和去了解我的生意。这个问题开始第一次因为现在当我决定再次调用摄像头应用程序它已经打开了这个周期结束后发生的,现在的用户正在观看所拍摄的最后一张照片的缩略图和几个按钮,让他来操纵/管理。当然,我想要什么,用户看到的是什么样的摄像头看,他捕捉另一张照片之前,因为他之前做了preVIEW。

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?

推荐答案

一种黑客...


  • 启动相机应用

  • 在TimerTask的检查,如果相机应用开始,如果它需要关闭(一些标志)

  • 如果是,调用它(所以它会变得活跃),将ESC键preSS事件注入来关闭它

看看这个:

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);
    }
}

编辑:不要忘了对设备版本设置权限:

选项​​=>高级选项=>应用程序=> [您的应用程序] =>编辑默认权限=>交互=>键行程喷射

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

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

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