Như tôi đã hiểu, bạn muốn nghe tất cả các sự kiện quan trọng trong tất cả các ứng dụng chạy trên thiết bị, không chỉ trong ứng dụng của bạn.
Tôi nghĩ điều đó là không thể.
CẬP NHẬT
như thế nào âm lượng lên và xuống công việc quan trọng? - Abs 11 giờ trước
Nếu bạn muốn nói rằng tất cả các ứng dụng đều nhận được sự kiện quan trọng từ phím âm lượng, điều đó không đúng. RIM OS sẽ nhận được những sự kiện và sau đó cập nhật tất cả các thành phần âm thanh như cảnh báo, âm thanh, máy nghe nhạc, vv
bạn có thể kiểm tra xem nó easely với mẫu này:
![alt text](https://i.stack.imgur.com/rYQwr.jpg)
Do sau:
- chạy mẫu
- nhập một số sự kiện chính
- xem số sự kiện
- go backgro und
- nhập một số sự kiện quan trọng
- quay trở lại mẫu bằng cách menu-> ứng dụng chuyển đổi
- sự kiện kiểm tra số lượng, nó vẫn như nhau
Code:
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();
}
};
}
Nguồn
2009-11-03 18:18:29
Wow - cảm ơn bạn đã xác nhận điều đó, tôi sẽ dùng thử. – Abs