我想制作一个应用程序来监听黑莓中的声音配置文件变化/音量变化。目标版本是 5、6、7 我在 Blackberry 的文档中进行了搜索,但一无所获。我在搜索过程中发现了两件事。
globaleventlistener 这需要该事件的 GUID,该事件未记录在事件 GUID 列表中。
通知管理器 Notificationmanager 可能会帮助注册其中一个。但我不知道如何用系统事件注册它。它还需要 GUID。
如果我错过了什么,请分享资源。我是黑莓开发的新手。请帮帮我。
谢谢,帕思沙阿
我想制作一个应用程序来监听黑莓中的声音配置文件变化/音量变化。目标版本是 5、6、7 我在 Blackberry 的文档中进行了搜索,但一无所获。我在搜索过程中发现了两件事。
globaleventlistener 这需要该事件的 GUID,该事件未记录在事件 GUID 列表中。
通知管理器 Notificationmanager 可能会帮助注册其中一个。但我不知道如何用系统事件注册它。它还需要 GUID。
如果我错过了什么,请分享资源。我是黑莓开发的新手。请帮帮我。
谢谢,帕思沙阿
package mypackage;
import net.rim.device.api.system.Application;
import net.rim.device.api.system.ApplicationDescriptor;
import net.rim.device.api.system.ApplicationManager;
import net.rim.device.api.system.Characters;
import net.rim.device.api.system.GlobalEventListener;
import net.rim.device.api.system.KeyHandlerRegistry;
import net.rim.device.api.system.KeyHandlerRegistryException;
import net.rim.device.api.ui.Keypad;
import net.rim.device.api.ui.UiApplication;
/**
* This class extends the UiApplication class, providing a
* graphical user interface.
*/
public class MyApp extends Application
{
/**
* Entry point for application
* @param args Command line arguments (not used)
*/
public static void main(String[] args)
{
// Create a new instance of the application and make the currently
// running thread the application's event dispatch thread.
MyApp theApp = new MyApp();
theApp.enterEventDispatcher();
}
/**
* Creates a new MyApp object
*/
public MyApp()
{
//Attach the keylistener to handle buttons pressed
addKeyListener(new Logger());
super.addGlobalEventListener(new GlobalListener());
try {
//Any Keypad Button will work to catch everything
KeyHandlerRegistry.register(getApplication(), Keypad.KEY_CONVENIENCE_1);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
System.out.println(e.toString());
e.printStackTrace();
} catch (KeyHandlerRegistryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
class GlobalListener implements GlobalEventListener{
public void eventOccurred(long guid, int data0, int data1, Object object0,
Object object1) {
//will catch and output all Global events to console
System.out.println("[GLOBAL LISTENER] Event = "+guid);
}
}
}
这应该可以处理你们俩都在寻找的东西。至于自定义keyListner:
package mypackage;
import net.rim.device.api.system.Characters;
import net.rim.device.api.system.EventInjector.KeyCodeEvent;
import net.rim.device.api.system.KeyListener;
import net.rim.device.api.ui.Keypad;
import net.rim.device.api.ui.container.MainScreen;
public final class Logger implements KeyListener {
//Set return to false to allow the program to pass the data to next keylistner
//All output to the console.
//Yet from testing only KeyUp and KeyDown are ever called and handle all special buttons
//Volume, Dial, EndCall, etc...
public boolean keyChar(char key, int status, int time) {
System.out.println("CHAR PRESSED: <"+key+"/>");
return false;
}
public boolean keyDown(int keycode, int time) {
System.out.println("KEY PRESSED (DOWN): < BUTTON="+getKey(keycode)+" ID="+keycode+" KEY VALUE= "+Keypad.key(keycode)+"/>");
return false;
}
public boolean keyRepeat(int keycode, int time) {
System.out.println("KEY REPEAT: < BUTTON="+getKey(keycode)+" ID="+keycode+"/>");
return false;
}
public boolean keyStatus(int keycode, int time) {
System.out.println("KEY STATUS: < BUTTON="+getKey(keycode)+" ID="+keycode+"/>");
return false;
}
public boolean keyUp(int keycode, int time) {
System.out.println("KEY PRESSED (UP): < BUTTON="+getKey(keycode)+" ID="+keycode+" KEY VALUE= "+Keypad.key(keycode)+"/>");
return false;
}
public String getKey(int keycode){
System.out.println("[EVENT ID] = "+ keycode);
//Converts the provided keycode into a value which can be compared to the keypad
//constants
keycode = Keypad.key(keycode);
System.out.println("[KEY ID] = "+ keycode);
String Result = null;
switch (keycode) {
case Keypad.KEY_ALT:
Result = "ALT";
break;
case Keypad.KEY_BACKLIGHT:
Result = "BACKLIGHT";
break;
case Keypad.KEY_BACKSPACE:
Result = "BACKSPACE";
break;
case Keypad.KEY_BACKWARD:
Result = "BACKWARD";
break;
case Keypad.KEY_CAMERA_FOCUS:
Result = "CAMERA_FOCUS";
break;
case Keypad.KEY_MIDDLE:
Result = "CONVENIENCE_1";
break;
case Keypad.KEY_CONVENIENCE_2:
Result = "CONVENIENCE_2";
break;
case Keypad.KEY_DELETE:
Result = "DELETE";
break;
case Keypad.KEY_END:
Result = "END_CALL_BUTTON";
break;
case Keypad.KEY_ENTER:
Result = "ENTER";
break;
case Keypad.KEY_ESCAPE:
Result = "ESCAPE";
break;
case Keypad.KEY_FORWARD:
Result = "FORWARD";
break;
case Keypad.KEY_LOCK:
Result = "LOCK";
break;
case Keypad.KEY_MENU:
Result = "MENU";
break;
case Keypad.KEY_NEXT:
Result = "NEXT";
break;
case Keypad.KEY_RIGHT_3:
Result = "RIGHT_3";
break;
case Keypad.KEY_SEND:
Result = "DIAL";
break;
case Keypad.KEY_SHIFT_LEFT:
Result = "SHIFT_LEFT";
break;
case Keypad.KEY_SHIFT_RIGHT:
Result = "SHIFT_RIGHT";
break;
case Keypad.KEY_SHIFT_X:
Result = "SHIFT_X";
break;
case Keypad.KEY_SPACE:
Result = "SPACE";
break;
case Keypad.KEY_SPEAKERPHONE:
Result = "SPEAKERPHONE";
break;
case Keypad.KEY_VOLUME_DOWN:
Result = "VOLUME_DOWN";
break;
case Keypad.KEY_VOLUME_UP:
Result = "VOLUME_UP";
break;
default:
Result = null;
break;
}
return Result;
}
}