我正在尝试编写一个使用 Android 4.4 KitKat 中添加的新红外 API 的小 Android 应用程序。→文档
我遇到了麻烦,因为我的应用程序因为没有响应而冻结并被杀死。
一些代码:
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
irService = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);
Log.d("transmit", "lets go");
irService.transmit(38000, new int[] { 70 });
Log.d("transmit", "done");
...
而这个logcat:
01-24 01:28:25.450: D/transmit(10551): lets go
01-24 01:29:14.610: D/transmit(10551): done
调用传输需要 30 多秒!
从文档:
public void transmit (int carrierFrequency, int[] pattern)
Added in API level 19
Tansmit and infrared pattern
This method is synchronous; when it returns the pattern has been transmitted. Only patterns shorter than 2 seconds will be transmitted.
Parameters
carrierFrequency The IR carrier frequency in Hertz.
pattern The alternating on/off pattern in microseconds to transmit. <---- this is wrong, see http://stackoverflow.com/questions/20244337
通过我手机的摄像头,我看到 IR-LED 一直在闪烁,所以我用红外传感器测量了实际传输时间(+ 表示爆发,- 表示空间):
+64
-88448
+1835
-789
+1557
-768
+1579
-768
+1579
-768
+149
-491
+1664
-555
+533
-555
+1664
-555
+1664
-555
+1664
-555
+533
-555
+533
-555
+533
-555
+533
-533
+555
-555
+533
-555
+533
-555
+533
-555
+533
-555
+1664
-555
+1664
-555
+533
-555
+533
-555
+533
-555
+533
-555
+533
-555
+1664
-555
+533
-555
+533
-555
+1664
-555
+1664
-555
+1664
-555
+1664
-555
+1664
-555
+555
-388053
+60672
-384
+341
-714709
+61419
-320
+277
-533
+213
-1188181
+42069
-491
+299
-733269
+38421
-427
+341
-736917
+38208
-427
+320
-737131
+37867
-491
+320
-737429
+37696
-512
+299
-737600
+37739
-597
+256
-737536
+36736
-533
+320
-1213376
+36181
-683
+235
-739008
+35605
-789
+213
-1214336
+36181
-683
+256
-1213824
+36651
-576
+277
-1213440
+36160
-619
+277
-1213930
+35797
-555
+320
-1214272
+36480
-555
+299
这是怎么回事?
我的设备是运行 OnmiROM 4.4 android 的 Galaxy Note 10.1 N8010。也许拥有兼容设备的人可以对此进行测试?