I am making an app that uses the IR blaster to control my TV. The app worked perfectly on my Galaxy s5 but not on my HTC ONE M8. I managed to modify the code to get it to work on the HTC and assumed this was just an isolated problem with HTC phones. However, once I upgraded to Lollipop the my IR blaster app no longer works for me. I have tested my app on different phones and it seems to be about a 50/50 chance if the IR blaster will work (yes I am only using devices that have IR blasters).
So my question is: Do I need to modify how I transmit with the IR blaster for different version of android?
The only reason that I can come up with for the IR blaster not working is maybe because there have been changes made to it from android version to version? So I need to modify my code dependent on which version of android the phone is on? Does anyone know if this is correct?
My code for transmitting on my Galaxy s5:
// Get a reference to the ConsumerIrManager
mCIR = (ConsumerIrManager)getSystemService(Context.CONSUMER_IR_SERVICE);
//If no ir blaster
if (!mCIR.hasIrEmitter()) {
Toast.makeText(getApplicationContext(), "Possibly No IR Blaster", Toast.LENGTH_LONG).show();
}
// otherise send signal
else {
mCIR.transmit(freq, PATTERN);
}
Then for HTC device I do everything the same, except modify my function for some reason.
Code for HTC Device:
mCIR.transmit(freq, translateForHTCDevices(PATTERN));
// Then here is how I modify it for HTC devices, just multiply each value by 27.7... weird right?...
private int[] translateForHTCDevices( int [] input) {
int [] result = new int[input.length];
for( int i = 0; i < input.length; i++) {
result[i] = (int) (input[i] * (27.7));
}
return result;
}
So what am I doing wrong here? Is this a problem with HTC devices or is it simply that the HTC device I was testing with is on a different version of Android and in fact the problem is my code does not work on some android versions?
Thanks for any help you can provide, I'm really stuck here on how I can make the IR blaster work on all devices with all android versions.