Android为TV端助力 完全解析模拟遥控器按键

复制代码
public class VirturlKeyPadCtr {
    private static Instrumentation mInstrumentation;

    public static void RC_ConttrollerAction(final int keyValue) {

    /**
     * Wrapper-function taking a KeyCode. A complete KeyStroke is DOWN and UP
     * Action on a key!
     */
    public static void simulateKeystroke(int KeyCode) {
        if (mInstrumentation == null) {
            mInstrumentation = new Instrumentation();
        }
        mInstrumentation.sendKeyDownUpSync(KeyCode);
    }
}

写一个类工具类到时候方便调用

调用的时候直接

VirturlKeyPadCtr.simulateKeystroke(realCode);

传人的参数为你的遥控器的KEY值,比如返回键就是KeyEvent.KEYCODE_BACK

Android 为TV端助力

相关推荐
m0_547486663 分钟前
《Java程序设计与实践 》全套PPT课件2026
java·开发语言
AFinalStone25 分钟前
Android 7系统无障碍服务(一)全景图与架构概览
android·无障碍服务
Android-Flutter28 分钟前
android 自定义view 详解
android·kotlin
土司大王38 分钟前
LeetCode hto100——字母异位词分组
java·算法·leetcode
码匠许师傅1 小时前
【C++ 面试真题】聊聊 C++ 中的 lambda 表达式
java·c++·面试
WAsbry1 小时前
协程任务的失败控制:取消、异常传播与Supervisor
android
QCodingDev1 小时前
Spring AI Alibaba ReAct Agent实战:从Tool Calling到Agent,企业AI复杂业务该如何设计?
java·人工智能·agent·ai编程·spring ai
Android打工仔1 小时前
从 finally 理解程序的控制流:它为什么不是 catch 后面的代码?
android·kotlin
随遇丿而安1 小时前
第15周:Service 全功能 + 后台优化
android
YXL1111YXL1 小时前
续体和状态机 —— suspend 函数的 CPS 变换
android·kotlin