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端助力

相关推荐
alexhilton14 小时前
使用FunctionGemma进行设备端函数调用
android·kotlin·android jetpack
冬奇Lab17 小时前
InputManagerService:输入事件分发与ANR机制
android·源码阅读
日月云棠20 小时前
各版本JDK对比:JDK 25 特性详解
java
张小潇20 小时前
AOSP15 Input专题InputManager源码分析
android·操作系统
用户83071968408221 小时前
Spring Boot 项目中日期处理的最佳实践
java·spring boot
JavaGuide21 小时前
Claude Opus 4.6 真的用不起了!我换成了国产 M2.5,实测真香!!
java·spring·ai·claude code
IT探险家21 小时前
Java 基本数据类型:8 种原始类型 + 数组 + 6 个新手必踩的坑
java
花花无缺1 天前
搞懂new 关键字(构造函数)和 .builder() 模式(建造者模式)创建对象
java
用户908324602731 天前
Spring Boot + MyBatis-Plus 多租户实战:从数据隔离到权限控制的完整方案
java·后端
桦说编程1 天前
实战分析 ConcurrentHashMap.computeIfAbsent 的锁冲突问题
java·后端·性能优化