android 红外

1.初始化manager:

private void initial() {
		// TODO Auto-generated method stub
		manager = (ConsumerIrManager) getSystemService(CONSUMER_IR_SERVICE);
	}

2.检测设备是否有红外装置:

if (mIrManager != null) {
			//Check whether the device has an infrared emitter.
			if (mIrManager.hasIrEmitter()) {
				
				//do something
				
				//Query the infrared transmitter's supported carrier frequencies
				CarrierFrequencyRange[] frequencyRanges = mIrManager.getCarrierFrequencies();
				if (frequencyRanges != null) {
					for (CarrierFrequencyRange frequency : frequencyRanges) {
						frequencyRange += String.format("%1$d ~ %2$d \n",
								frequency.getMinFrequency(), frequency.getMaxFrequency());
						//do something
					}
				}
			}
		}

 3.transmit

//This method is synchronous; when it returns the pattern has been transmitted. Only patterns shorter than 2 seconds will be transmitted.
manager.transmit(frequency, pattern);

 

猜你喜欢

转载自bgj.iteye.com/blog/2157652
今日推荐