android检查是否插入OTG鼠标或键盘代码
来源:互联网 发布:网络四大名著三大奇书 编辑:程序博客网 时间:2024/06/05 10:14
检查otg设备是否是鼠标或键盘
首先需要继承InputManager.InputDeviceListener:
public class OTGTest extends BaseActivity implements InputManager.InputDeviceListener
private InputManager mIm; mIm = (InputManager) getSystemService(INPUT_SERVICE); mIm.registerInputDeviceListener(this, null); if(mIm == null) { mIm = (InputManager) getSystemService(INPUT_SERVICE); mIm.registerInputDeviceListener(this, null); } final int[] devices = InputDevice.getDeviceIds(); for (int i = 0; i < devices.length; i++) { InputDevice device = InputDevice.getDevice(devices[i]); if (device != null && !device.isVirtual() && device.isExternal()) { if(device.getName().contains("Mouse") || device.getName().contains("Keyboard")) { Log.d(TAG, "device.getName()=" + device.getName() + " device.getId() " + device.getId() + " getDescriptor " + device.getDescriptor()); break; } } }
实现父类的方法:
@Overridepublic void onInputDeviceAdded(int deviceId) { Log.d("huasong", "onInputDeviceRemoved " + deviceId); InputDevice device = InputDevice.getDevice(deviceId); if (device != null && !device.isVirtual() && (device.isFullKeyboard() || device.isExternal())) { if(device.getName().contains("Mouse") || device.getName().contains("Keyboard")) { Log.d(TAG, "device.getName()=" + device.getName() + " device.getId() " + device.getId() + " getDescriptor " + device.getDescriptor()); } }}@Overridepublic void onInputDeviceChanged(int deviceId) {}@Overridepublic void onInputDeviceRemoved(int deviceId) {}
1 0
- android检查是否插入OTG鼠标或键盘代码
- Syser:检查是否存在鼠标和键盘
- Windows API了解用户是否在使用鼠标或键盘
- Windows API了解用户是否在使用鼠标或键盘
- Windows API了解用户是否在使用鼠标或键盘
- 安卓OTG连接键盘鼠标输入法切换方法(搜狗)
- Android系统插入OTG后不休眠
- Android系统插入OTG后不休眠
- Android系统插入OTG后不休眠
- linux检查网线是否插入
- linux检查网线是否插入
- android 模拟键盘鼠标
- android模拟键盘鼠标
- Android检查是否联网
- UGUI检查鼠标是否点击到UI
- php中检查文件或目录是否存在的代码小结
- 检查intent是否存在代码
- android OTG
- Android使用AttributeSet自定义控件的方法
- 《剑指Offer》读书笔记06:旋转数组的最小数字
- 教你如何在Mac上搭建自己的服务器——Nginx
- otter(三)--同步过程小解
- 简单的图片切换
- android检查是否插入OTG鼠标或键盘代码
- Java web如何连接sql数据库并实现网页输入数据和数据库的互动。
- 基于Thinkphp3.2.3框架开发的调试方法总结
- Linux存储在线管理(一)FC磁盘设备管理
- canvas画笔(涂鸦)
- Selenium等待元素的处理方法
- redis优化配置和redis.conf说明
- 数据库的垂直切分和水平切分
- android 5.0 实现xml文件的解释,读写操作