红外发射器和Android 5.0

我正在使用Android 5.0运行的Galaxy S5上的红外发射器出现问题。

在我将它更新到5.0之前,我的应用程序完全在我的手机上工作,但现在,我想要管理的设备没有任何反应。 当我点击我的应用程序发送红外代码时,指示灯闪烁表示红外管理器已启动,并且可以接收到与我的示波器连接的红外光电二极管的信号。 不幸的是,我得到的信号的形状与它应该是非常不同的。

我可以补充说,在Android 4.4.2平板电脑上运行的代码仍然可以正常工作。

为了帮助回答我的问题,我的代码示例如下:

private String commande="0000 0070 0000 0032 0080 003F 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 "
+ "0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 "
+ "0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0030 0010 0030 0010 0030 0010 0030 "
+ "0010 0010 0010 0010 0010 0010 0010 0030 0010 0030 0010 0030 0010 0030 0010 0030 0010 0010 0010 0030 0010 0A98";

IRManager=(ConsumerIrManager)activité.getSystemService(Context.CONSUMER_IR_SERVICE);
code=commandConversion(commande);
IRManager.transmit(code.getFrequency(),code.getCodes());

private RemoteCommandeCode commandConversion(String command) {
    List<String> list;
    RemoteCommandeCode code;
    int frequency;

    list= new ArrayList<String>(Arrays.asList(command.split(" ")));

    list.remove(0); // dummy

    frequency = Integer.parseInt(liste.remove(0), 16); // frequency

    list.remove(0); // seq1

    list.remove(0); // seq2

    code=new RemoteCommandeCode(list.size());

    for (int i = 0; i < list.size(); i++) {
        code.setCode(i,Integer.parseInt(list.get(i), 16));
    }

    frequency = (int) (1000000 / (frequency * 0.241246));

    code.setFrequency(frequency);

    return(code);
}

public class RemoteCommandeCode {
    private int fréquence;
    private int [] codes;

    public RemoteCommandeCode(int nombreCodes){
        codes=new int[nombreCodes];
    }

    public int getFrequency() {
        return frequency;
    }

    public void setFrequency(int frequency) {
        this.frequency = frequency;
    }

    public int [] getCodes() {
        return codes;
    }

    public void setCodes(int [] codes) {
        this.codes = codes;
    }

    public void setCode(int i,int code){
        codes[i]=code;
    }
}

正如所问,简单代码“0000 0070 0000 0003 0010 0020 0010 0020 0010 0020”发出的信号图像,我在4.4.2: Android 4.4.2上的信号

和Android 5.0上: 信号在Android 5.0上


此方法将修复所有Android版本的IR问题

/*
 * preforms some calculations on the codesets we have in order to make them work with certain models of phone.
 *
 * HTC devices need formula 1
 * Samsungs want formula 2
 *
 * Samsung Pre-4.4.3 want nothing, so just return the input data
 *
 */
private static int[] string2dec(int[] irData, int frequency) {
    int formula = shouldEquationRun();

    //Should we run any computations on the irData?
    if (formula != 0) {
        for (int i = 0; i < irData.length; i++) {
            if (formula == 1) {
                irData[i] = irData[i] * (1000000/frequency);//the brackets should avoid an arithmetic overflow
            } else if (formula == 2) {
                irData[i] = (int) Math.ceil(irData[i] * 26.27272727272727); //this is the samsung formula as per http://developer.samsung.com/android/technical-docs/Workaround-to-solve-issues-with-the-ConsumerIrManager-in-Android-version-lower-than-4-4-3-KitKat
            }
        }
    }
    return irData;
}

/*
 * This method figures out if we should be running the equation in string2dec,
 * which is based on the type of device. Some need it to run in order to function, some need it NOT to run
 *
 * HTC needs it on (HTC One M8)
 * Samsung needs occasionally a special formula, depending on the version
 * Android 5.0+ need it on. 
 * Other devices DO NOT need anything special.
 */
private static int shouldEquationRun() {
    //Some notes on what Build.X will return
    //System.out.println(Build.MODEL); //One M8
    //System.out.println(Build.MANUFACTURER); //htc
    //System.out.println(Build.VERSION.SDK_INT); //19

    //Samsung's way of finding out if their OS is too new to work without a formula:
    //int lastIdx = Build.VERSION.RELEASE.lastIndexOf(".");
    //System.out.println(Build.VERSION.RELEASE.substring(lastIdx+1)); //4

    //handle HTC
    if (Build.MANUFACTURER.equalsIgnoreCase("HTC")) {
        return 1;
    }
    //handle Lollipop (Android 5.0.1 == SDK 21) / beyond
    if (Build.VERSION.SDK_INT >= 21) {
        return 1;
    }
    //handle Samsung PRE-Android 5
    if (Build.MANUFACTURER.equalsIgnoreCase("SAMSUNG")) {
        if (Build.VERSION.SDK_INT >= 19) {
            int lastIdx = Build.VERSION.RELEASE.lastIndexOf(".");
            int VERSION_MR = Integer.valueOf(Build.VERSION.RELEASE.substring(lastIdx + 1));
            if (VERSION_MR < 3) {
                // Before version of Android 4.4.2
                //Note: NO formula here, not even the other one
                return 0;
            } else {
                // Later version of Android 4.4.3
                //run the special samsung formula here
                return 2;
            }
        }
    }
    //if something else...
    return 0;
}

*编辑:感谢OP的帮助,我能够弄清楚如何解决这个问题。 这个答案现在应该解决这个问题。

链接地址: http://www.djcxy.com/p/25169.html

上一篇: IR emitter and Android 5.0

下一篇: Dragging elements on a scaled div