因为我一个小伙伴一起搞一个项目,他负责硬件我负责android。然后要在手机上实现红外线遥控的功能。在网上找了很多资料终于集众家所长,搞定了。
package com.example.zmx.myapplication;
import android.annotation.TargetApi;
import android.os.Build;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.hardware.ConsumerIrManager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
private ConsumerIrManager IR;
private TextView show;
private Button btn_open;
private Button btn_close;
private Button btn_shake;
private Button btn_shake_off;
boolean IRBack;
//各种功能的编码段
int[] pattern = new int[] { //0x45 开
9000,4500,
560,565, 560,565, 560,565, 560,565, 560,565, 560,565, 560,565, 560,565,
560,1690, 560,1690, 560,1690, 560,1690, 560,1690, 560,1690, 560,1690, 560,1690,
560,1690, 560,565, 560,1690, 560,565, 560,565, 560,565, 560,1690, 560,565,
560,565, 560,1690, 560,565, 565,1690, 565,1690, 560,1690, 560,565, 560,1690,
9000,2250, 2250,94000, 9000,2250, 2250,94000};
int[] pattern1 = new int[] { //0x46 关
9000,4500,
560,565, 560,565, 560,565, 560,565, 560,565,