黑莓声音配置文件变更/音量变更监听器
我想制作监听黑莓声音配置文件变更/音量变更的应用程序。目标版本是5,6,7 我在黑莓的文档中搜索,但什么也没找到。 我在搜索过程中发现了两件事。黑莓声音配置文件变更/音量变更监听器
globaleventlistener 这需要一个事件的GUID,这个事件是不是在事件列表GUID documented。
通知管理器 Notificationmanager可能会帮助其中一个注册表。 但我不知道如何注册系统事件。它也需要GUID。
请分享资源,如果我错过了什么。 我是黑莓开发的新手。请帮助我。
感谢, PARTH沙阿
回答:
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;
}
}
以上是 黑莓声音配置文件变更/音量变更监听器 的全部内容, 来源链接: utcz.com/qa/261972.html