Ir Emitter and Android 5.0

IR emitter and Android 5.0

This method will fix the IR problems for all Android versions

/*
* 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;
}

*Edit: Thanks to the OP's help, I was able to figure out how to fix this. This answer should now solve this problem.

Java for android error: IR emitter not available in a device that HAS IR support

It looks like LG has it's own IR blaster SDK. The LG QRemote SDK.

http://developer.lge.com/resource/mobile/RetrieveOverview.dev?categoryTypeCode=ANRS

In the end of the list.

App force closes when using IR sensor of phone

You can initialize it like this

  val value = getSystemService(Context.CONSUMER_IR_SERVICE) as ConsumerIrManager

ConsumerIrManager.transmit broken in Lollipop?

As @IvanTellez says, a change was made in Android in respect to this functionality. Strangely, when I had it outputting simple IR signals (for troubleshooting purposes), the function behaves as shown above (erratically, wrong carrier frequency, etc). When I eventually returned to normal types of IR signals, it worked correctly.

HTC IR API Lollipop

The HtcConsumerIr app doesn't work on Lollipop because it only uses the HTC library if you have KitKat.
If you open ConsumerIrManagerCompat.java and change this line:

if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT
&& hasPackage("com.htc.cirmodule", context)) {
return new ConsumerIrManagerHtc(context);
} else {
return new ConsumerIrManagerBase(context);
}

to this:

if (hasPackage("com.htc.cirmodule", context)) {
return new ConsumerIrManagerHtc(context);
} else {
return new ConsumerIrManagerBase(context);
}

it will work.

I'm currently trying to get my app working again after upgrading to Lollipop. It was all working fine in KitKat without needing to use the HTC library.
I've not got it completely working yet, but I have got it transmitting. Seems we're back to using pulse counts instead of durations too.



Related Topics



Leave a reply



Submit