安卓发送发外代码(三星NOTE3测试成功,华为荣耀成功)。有些手机不支持,必须有红外模块,这是安卓内核里面的隐藏API。
package com.remotefairy.model;
import java.lang.reflect.Method;
import com.example.hx.MainAppliaction;
public class KitKatIR {
private Method transmit = null;
private Object ConsumerIrManager = null;
public boolean hasIrEmitter() {
Object ConsumerIrManager = MainAppliaction.getAppliaction()
.getSystemService("consumer_ir");
Class<?> clazz = ConsumerIrManager.getClass();
Method[] methods = clazz.getMethods();
Method hasIrEmitter = null;
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().indexOf("hasIrEmitter") != -1) {
hasIrEmitter = methods[i];
break;
}
}
return hasIrEmitter != null;
}
public void sendIRCode(int paramInt, int[] paramArrayOfInt) {
try {
if (transmit == null) {
ConsumerIrManager = MainAppliaction.getAppliaction()
.getSystemService("consumer_ir");
Class<?> clazz = ConsumerIrManager.getClass();
Method[] methods = clazz.getMethods();
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().indexOf("transmit") != -1) {
transmit = methods[i];
break;
}
}
}
transmit.invoke(ConsumerIrManager, new Object[] { paramInt,
paramArrayOfInt });
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
测试代码
private int hz = 38000;
private static final int CODE1 = 13;
private static final int CODE2 = 32;
private static final int CODE3 = 72;
private static final int CODE4 = 1800;
private static final int CODE5 = 1650;
private static int[] pattern = { CODE1, CODE3, CODE1, CODE2, CODE1, CODE2,
CODE1, CODE2, CODE1, CODE2, CODE1, CODE2, CODE1, CODE2, CODE1,
CODE3, CODE1, CODE2, CODE1, CODE3, CODE1, CODE2, CODE1, CODE2,
CODE1, CODE2, CODE1, CODE3, CODE1, CODE2, CODE1, CODE4, CODE1,
CODE3, CODE1, CODE2, CODE1, CODE2, CODE1, CODE2, CODE1, CODE2,
CODE1, CODE3, CODE1, CODE3, CODE1, CODE2, CODE1, CODE3, CODE1,
CODE2, CODE1, CODE3, CODE1, CODE3, CODE1, CODE3, CODE1, CODE2,
CODE1, CODE3, CODE1, CODE5, CODE1, CODE3, CODE1, CODE2, CODE1,
CODE2, CODE1, CODE2, CODE1, CODE2, CODE1, CODE2, CODE1, CODE2,
CODE1, CODE3, CODE1, CODE2, CODE1, CODE3, CODE1, CODE2, CODE1,
CODE2, CODE1, CODE2, CODE1, CODE3, CODE1, CODE2, CODE1, CODE4,
CODE1, CODE3, CODE1, CODE2, CODE1, CODE2, CODE1, CODE2, CODE1,
CODE2, CODE1, CODE3, CODE1, CODE3, CODE1, CODE2, CODE1, CODE3,
CODE1, CODE2, CODE1, CODE3, CODE1, CODE3, CODE1, CODE3, CODE1,
CODE2, CODE1, CODE3, CODE1 };
本文链接:https://it72.com:4443/108.htm