BlackBerry 编程 - 侧面硬件音量按钮

发布于 2024-10-02 23:14:28 字数 36 浏览 0 评论 0原文

有没有办法知道用户是否按下手机侧面的两个硬件音量按钮之一?

Is there a way to know if users press one of the two hardware volume buttons on the side of the phone?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

诗笺 2024-10-09 23:14:28

在 MainScreen 或 FullScreen 类上,重写以下方法:

protected boolean keyControl(char key, int status, int time) {
    switch (key) {
        case Characters.CONTROL_VOLUME_UP:
            // Do something
            return true;
        case Characters.CONTROL_VOLUME_DOWN:
            // Do something
            return true;
        default:
            return super.keyCharUnhandled(key, status, time);
    }
}

需要注意的是,这仅在您的应用程序和屏幕位于前台时才有效。如果您希望允许用户在应用程序处于后台时使用音量键,则需要使用 BlackBerry Media Actions API,仅适用于 5.0 及更高版本。

On your MainScreen or FullScreen class, override the following method:

protected boolean keyControl(char key, int status, int time) {
    switch (key) {
        case Characters.CONTROL_VOLUME_UP:
            // Do something
            return true;
        case Characters.CONTROL_VOLUME_DOWN:
            // Do something
            return true;
        default:
            return super.keyCharUnhandled(key, status, time);
    }
}

The caveat being that this only works when your app and that screen are in the foreground. If you want to allow users to use the volume keys while your app is in the background, you'll need to use the BlackBerry Media Actions API, which is only available on 5.0 and above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文