4

I need to use the infrared transmitter on an HTC One device. Before the lolipop update I could do this no problem, but now my code does not work.

    ConsumerIrManager mCIR = (ConsumerIrManager)getSystemService(Context.CONSUMER_IR_SERVICE);
    mCIR.transmit(freq, pat);

where freq and pattern are the required values to power on my TV (from the manufacturer)

I do not get any errors running this code, the only problem is that the infrared transmitter does not light up on HTC one devices. ( looking at ir blaster through camera ). I dont understand, the exact same code works on galaxy s5 devices. I would appreciate any help from someone who can get infrared to work on HTC one devices.

gre_gor
  • 6,669
  • 9
  • 47
  • 52
alexward1230
  • 579
  • 3
  • 8
  • 25
  • http://stackoverflow.com/questions/28831462/consumerirmanager-not-working-on-htc-m8-lollipop – dljava May 23 '15 at 11:00

5 Answers5

4

Yes, this issue seems to have been reported on the official bug tracker for Android.

I am developing an App which uses the official Consumer IR API introduced in Android 4.4 KitKat. Since the Lollipop rollouts for popular devices like the HTC One M8 or Samsung Galaxy S5 I am getting many reports from users of said devices that my App is not working on Lollipop. I do not own a Lollipop device myself, but I borrowed an M8 and did some tests.

It seems like the method ConsumerIrManager.transmit() is a no-op on Lollipop. No matter was pattern is given, it returns instantly.

Before discovering that Galaxy S5 users have the same problem, I contacted the HTC support on that matter and was told to contact the Google support.

It would seem S5 devices are getting the same issue as well, although it's hard to tell because developers are getting contradictory reports from S5 owners.

Here is an HTC-only fix that someone found for his M7 after it stopped working because of a Lollipop update. He basically reverted to an earlier version of the IR HTC API before they had switched to the official Google's api.

Otherwise, you should star the issue on the bug tracker, and perhaps point your own users to do the same. The more people star this issue, the higher priority it will be given.

Community
  • 1
  • 1
Stephan Branczyk
  • 9,363
  • 2
  • 33
  • 49
  • Damn, I've just updated my Galaxy S4 to Lollipop, and an IR blaster app I've written just stopped working... I guess it's a bug. – Mauker Jul 01 '15 at 23:48
0

I've just fixed this problem, for Samsung devices:

Before Android 4.4.3 each element of the pattern is the number of cycles for the on/off pulse.

For Android 4.4.3 and above each element of the pattern if the number of micro seconds for the on/off pulse.

Example:

To transmit a wave 0.5s on, 0.5 off, 0.5 on, at 38000Hz

Before Android 4.4.3 your pattern would be [19000, 190000, 19000] - The 19000 comes from 0.5s*38000Hz

For Android 4.4.3+ your pattern would be [500000, 500000, 500000] - that is you convert each time to microseconds(us).

I'm going to blame Google on this one: Before 4.4.3 was released their API said to use the number of cycles, after 4.4.3 the changed it to say to use microseconds(us), Samsung simply followed the API thus breaking our apps.

SoftwareDev
  • 674
  • 1
  • 6
  • 14
0

*Edit: UPDATED version of this fix can be found here: https://stackoverflow.com/a/28934938/1042362

Give this a shot:

/*
 * 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; 
            } 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;
}
Community
  • 1
  • 1
Dwebtron
  • 777
  • 13
  • 27
  • Thanks for the help. I tried that and it only works on htc one before the lollipop update. After update the IR blaster doesnt even light up :( any more help would be greatly appreciated. – alexward1230 May 23 '15 at 02:15
  • @alexward1230 have you solved your problem? I have an ir app that on HTC one m7 android 5.1 doesn't work on m8 all ok on samsung all ok. I don't know what to do more... – GMG Dec 06 '15 at 19:21
  • @GMG Did you try the answer above? I had updated it since he tried that code, so it should be a little different. – Dwebtron Dec 07 '15 at 19:46
0

The stock remote has been stopped since end of April. Download the Peel app which is branded version used on M9.

Paddy
  • 9
  • 1
0

My experience on HTC One M7: 1) KitKat 4.4.3 the ConsumerIRManager code worked fine, passing an array of microseconds.

2) Updated to Lolipop 5.0.2 and there was no transmission at all from the IR Led, the no-op problem. I refactored my code to use the HTC API, which requires the waveform in "clock ticks" instead of direct microseconds. All is working now.

It seems we cannot use the ConsumerIRManager on HTC One except for very specific versions, i.e. 4.4.3.

FalkiD
  • 11
  • 2
  • Can you provide information on how to use the HTC-specific API and how to get any needed libraries, etc? – David White Dec 30 '19 at 00:42
  • Wow, so sorry I missed this request so long ago. Here's a module I wrote that works well using the HTC IR library. I got the library itself from joining the HTCDev developer network on HTC's website many years ago. Let me know if you still need the HTCIR.jar file. – FalkiD Aug 19 '21 at 14:03
  • Ran over the time limit. Here's my complete response:Wow, so sorry I missed this request so long ago. Here's a link to module I wrote that works well using the HTC IR library. I got the library itself from joining the HTCDev developer network on HTC's website many years ago. The HTCIR.jar file is in the shared directory also. At one point I had trouble w/the jar file and recreated another one for some reason. I think it was some kind of duplicate Android manifest issue. https://www.dropbox.com/sh/nhebktyjc6owmlt/AABjYvfJ4rYknRuYh0t_83D3a?dl=0 – FalkiD Aug 19 '21 at 14:19