在Android 4.4无法正常工作后,IR传输ConsumerIrManager类

joy*_*nks 9 java android infrared

我建立了一个Android应用程序,以控制我的空调,它曾经在Android 4.1(我使用HTC M8手机)工作正常,现在升级到5.0棒棒糖后它停止工作我附加了一个样本片段.

没有调试错误,它表示IR已传输.

- 空调品牌三星(包括开关的红外代码)

PS:我已经模拟了所有连接的代码,

//To hold my codes for remote say on, off temp+, temp-, swing etc
public class TransmissionCodes{
    private int[] transmission;
    private int frequency;

    //+getters +setters +constructor
}

//To hold all the TransmissionCodes objects
SparseArray<TransmissionCodes> sequence ;

//power on
sequence.put(0,     new TransmissionCodes(38000,    "123,339,23,54,23,14,23,16,21,14,21,16,21,14,23,16,21,16,21,14,23,53,23,15,22,16,21,54,23,14,23,16,21,16,21,54,23,54,23,53,23,54,23,14,23,54,23,14,23,54,22,54,23,16,21,16,21,14,23,14,23,16,21,16,21,54,23,54,23,15,22,15,22,14,23,14,23,14,23,14,23,53,23,54,23,14,23,14,23,16,21,54,23,14,23,16,21,14,23,16,21,14,23,16,21,14,23,53,23,53,23,54,23,54,23,2500"));
//power off
sequence.put(1,     new TransmissionCodes(38000,    "123,339,23,54,23,14,23,16,21,14,21,16,21,14,23,16,21,16,21,14,23,53,23,15,22,16,21,54,23,14,23,16,21,16,21,54,23,54,23,53,23,54,23,14,23,54,23,14,23,54,22,54,23,16,21,16,21,14,23,14,23,16,21,16,21,54,23,54,23,15,22,15,22,14,23,14,23,14,23,14,23,53,23,54,23,14,23,14,23,16,21,54,23,14,23,16,21,14,23,16,21,14,23,16,21,14,23,53,23,53,23,54,23,54,23,2500"));


//IR call in main Activity
findViewById(R.id.button).post(new Runnable() {
    public void run() {
        ConsumerIrManager mCIR = (ConsumerIrManager) getSystemService(android.content.Context.CONSUMER_IR_SERVICE);
        mCIR.transmit(sequence.getFrequency, sequence.getTransmission);
    }
});
Run Code Online (Sandbox Code Playgroud)

这是一个接近但无法帮助的链接. Stack Overflow参考

有人可以帮我把东西放在一起,或者我错过了什么?

joy*_*nks 1

好吧,最初当我构建它时,API 支持脉冲,现在它们支持以微秒为单位的持续时间,因为我的原始数据是以位为单位的,所以我没有触及它,而是在我的 getter 中,我确实选择了修改和传输,所以公式成立duration = (1000000 / frequency) * pulse并传输持续时间而非脉冲的数组。

//To hold my codes for remote say on, off temp+, temp-, swing etc
public class TransmissionCodes{
    private int[] transmission; //will use to store and send transmssion
    private int frequency;//fed from my properties file
    private String countPattern; // Fed as string from my properties file

    //This modification in the getter did the trick
    private int[] getTransmission() {
        int pulses = 1000000/this.frequency;
        String[] countArray = this.countPattern.split(",");
        int[] anotherFix = new int[countArray.length];
        for (int i = 0; i < countArray.length; i++) {
            anotherFix[i] = Integer.parseInt(countArray[i]) * pulses;
        }
        return anotherFix;
    }
    //+getters +setters +constructor
}

//To hold all the TransmissionCodes objects
SparseArray<TransmissionCodes> sequence ;

//power on
sequence.put(0,     new TransmissionCodes(38000,    "123,339,23,54,23,14,23,16,21,14,21,16,21,14,23,16,21,16,21,14,23,53,23,15,22,16,21,54,23,14,23,16,21,16,21,54,23,54,23,53,23,54,23,14,23,54,23,14,23,54,22,54,23,16,21,16,21,14,23,14,23,16,21,16,21,54,23,54,23,15,22,15,22,14,23,14,23,14,23,14,23,53,23,54,23,14,23,14,23,16,21,54,23,14,23,16,21,14,23,16,21,14,23,16,21,14,23,53,23,53,23,54,23,54,23,2500"));
//power off
sequence.put(1,     new TransmissionCodes(38000,    "123,339,23,54,23,14,23,16,21,14,21,16,21,14,23,16,21,16,21,14,23,53,23,15,22,16,21,54,23,14,23,16,21,16,21,54,23,54,23,53,23,54,23,14,23,54,23,14,23,54,22,54,23,16,21,16,21,14,23,14,23,16,21,16,21,54,23,54,23,15,22,15,22,14,23,14,23,14,23,14,23,53,23,54,23,14,23,14,23,16,21,54,23,14,23,16,21,14,23,16,21,14,23,16,21,14,23,53,23,53,23,54,23,54,23,2500"));


//IR call in main Activity
findViewById(R.id.button).post(new Runnable() {
    public void run() {
        ConsumerIrManager mCIR = (ConsumerIrManager) getSystemService(android.content.Context.CONSUMER_IR_SERVICE);
        mCIR.transmit(sequence.getFrequency, sequence.getTransmission);
    }
});
Run Code Online (Sandbox Code Playgroud)

不过,我正在寻找可以应用于 HTC 的修复程序,因为此修复程序仅适用于具有 IR 的三星手机。也没有检查 LG 手机。但根据我的研究,三星和 LG 应该可以合作,HTC 在 IR API 方面处于领先地位。向外看