简体   繁体   English

黑莓手机中的声音配置文件更改/音量更改监听器

[英]sound profile change/volume change listener in blackberry

I want to make an application that listen to the sound profile change/volume change in blackberry. 我想制作一个监听黑莓中声音配置文件更改/音量更改的应用程序。 Targeting versions are 5,6,7 I had search in documentation of Blackberry but found nothing. 定位版本为5,6,7,我在Blackberry的文档中进行了搜索,但未找到任何内容。 two things i found during searching. 我在搜索过程中发现了两件事。

  1. globaleventlistener This needs GUID of that event, this event is not documented in event GUID list. globaleventlistener这需要该事件的GUID,该事件未记录在事件GUID列表中。

  2. Notification manager Notificationmanager might help with one of the register. 通知管理器Notificationmanager可能会帮助其中之一的注册。 but i dont know how to register it with system events. 但是我不知道如何在系统事件中注册它。 It also needs GUID. 它还需要GUID。

please share resource if i missed something. 如果我错过了什么,请分享资源。 I am new to blackberry development. 我是黑莓开发的新手。 please help me out. 请帮帮我。

Thanks, Parth Shah 谢谢,Parth Shah

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

    }

}

} }

This should handle what you both are looking for. 这应该可以解决你们俩都在寻找的东西。 As for the custom keyListner: 至于自定义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;
}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM