BlackBerry アプリの開発は初めてです。BlackBerry (私の場合は 8900) がオンで、すべての画面でキープレス イベントをリッスンできるようにしたいのですが、これは可能ですか?
もしそうなら、誰かが私を正しい方向に導くことは素晴らしいことです. 私はすでに Interface KeyListener を見ています。
import net.rim.device.api.system.*;
皆さんありがとう
BlackBerry アプリの開発は初めてです。BlackBerry (私の場合は 8900) がオンで、すべての画面でキープレス イベントをリッスンできるようにしたいのですが、これは可能ですか?
もしそうなら、誰かが私を正しい方向に導くことは素晴らしいことです. 私はすでに Interface KeyListener を見ています。
import net.rim.device.api.system.*;
皆さんありがとう
私が理解しているように、アプリケーションだけでなく、デバイスで実行されているすべてのアプリケーションですべての主要なイベントをリッスンする必要があります。
無理だと思います。
アップデート
音量の上下キーはどのように機能しますか? – Abs 11 時間前
すべてのアプリケーションがボリューム キーからキー イベントを受信すると言いたい場合、それは正しくありません。RIM OS はこれらのイベントを受け取り、アラート、オーディオ、プレーヤーなどのすべてのオーディオ コンポーネントを更新します。
このサンプルで簡単に確認できます。
以下を実行します。
コード:
import net.rim.device.api.system.KeyListener;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.container.MainScreen;
public class KeyListenerApp extends UiApplication implements KeyListener {
Scr mScreen;
public KeyListenerApp() {
mScreen = new Scr();
pushScreen(mScreen);
addKeyListener(this);
}
public static void main(String[] args) {
KeyListenerApp app = new KeyListenerApp();
app.enterEventDispatcher();
}
private void updateScreen(final String text) {
mScreen.addLine(text);
}
public boolean keyChar(char key, int status, int time) {
updateScreen("keyChar " + key);
return true;
}
public boolean keyDown(int keycode, int time) {
updateScreen("keyDown " + keycode);
return true;
}
public boolean keyRepeat(int keycode, int time) {
updateScreen("keyRepeat " + keycode);
return true;
}
public boolean keyStatus(int keycode, int time) {
updateScreen("keyStatus " + keycode);
return true;
}
public boolean keyUp(int keycode, int time) {
updateScreen("keyUp " + keycode);
return true;
}
}
class Scr extends MainScreen {
int mEventsCount = 0;
LabelField mEventsStatistic = new LabelField("events count: "
+ String.valueOf(mEventsCount));
public Scr() {
super(VERTICAL_SCROLL | VERTICAL_SCROLLBAR);
add(mEventsStatistic);
}
public void addLine(final String text) {
getApplication().invokeLater(new Runnable() {
public void run() {
mEventsStatistic.setText("events count: "
+ String.valueOf(++mEventsCount));
insert(new LabelField(text), 1);
}
});
}
protected void makeMenu(Menu menu, int instance) {
super.makeMenu(menu, instance);
menu.add(goBGMenuItem);
}
MenuItem goBGMenuItem = new MenuItem("go backgroun", 0, 0) {
public void run() {
getApplication().requestBackground();
}
};
}
上記のコードは確かに機能しますが、落とし穴があります。通話処理、SMS、着信ブラウジングなどのネイティブ アプリでのキーの押下をトラップすることはできません。システムがこれらのアプリに対してグローバル イベントを生成するため。アプリがバックグラウンドにあるときにクリックのルーチンを定義できるようですが、そのルーチンの機能はアプリケーションにのみローカライズされます。他のアプリ自体には影響しません。
これは私がそれがうまくいくと想像する方法です
UiApplication
するApplication
Keylistener
(必要に応じて拡張することもできThread
ます)KeyListener
実装をアプリケーションに追加しますaddKeyListener()