国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android編程調用紅外線遙控功能示例

2019-12-12 02:13:10
字體:
來源:轉載
供稿:網友

本文實例講述了Android編程調用紅外線遙控功能。分享給大家供大家參考,具體如下:

Android API Demos中有紅外線遙控的小例子,在網上找了很久相關的資料,發現比較少,或許找的方法不對。

Github上有一個與之相關的開源項目https://github.com/timnew/AndroidInfrared,還沒來得及學習。希望有相關資料或學習項目的大神們多指導 。

/** * Android紅外線遙控官方Demo *  * @description: * @author ldm * @date 2016-4-28 下午5:06:28 */public class ConsumerIrActivity extends Activity {  private static final String TAG = "ConsumerIrTest";  private TextView mFreqsText;  // Android4.4之后 紅外遙控ConsumerIrManager,可以被小米4調用  private ConsumerIrManager mCIR;  @SuppressLint("InlinedApi")  @Override  protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.consumer_ir);    // 獲取系統的紅外遙控服務    mCIR = (ConsumerIrManager) getSystemService(Context.CONSUMER_IR_SERVICE);    initViewsAndEvents();  }  private void initViewsAndEvents() {    findViewById(R.id.send_button).setOnClickListener(mSendClickListener);    findViewById(R.id.get_freqs_button)        .setOnClickListener(mOnClickListener);    mFreqsText = (TextView) findViewById(R.id.freqs_text);  }  View.OnClickListener mSendClickListener = new View.OnClickListener() {    @TargetApi(Build.VERSION_CODES.KITKAT)    public void onClick(View v) {      if (!mCIR.hasIrEmitter()) {        Log.e(TAG, "未找到紅外發身器!");        return;      }      // 一種交替的載波序列模式,通過毫秒測量      int[] pattern = { 1901, 4453, 625, 1614, 625, 1588, 625, 1614, 625,          442, 625, 442, 625, 468, 625, 442, 625, 494, 572, 1614,          625, 1588, 625, 1614, 625, 494, 572, 442, 651, 442, 625,          442, 625, 442, 625, 1614, 625, 1588, 651, 1588, 625, 442,          625, 494, 598, 442, 625, 442, 625, 520, 572, 442, 625, 442,          625, 442, 651, 1588, 625, 1614, 625, 1588, 625, 1614, 625,          1588, 625, 48958 };      // 在38.4KHz條件下進行模式轉換      mCIR.transmit(38400, pattern);    }  };  @SuppressLint("NewApi")  View.OnClickListener mOnClickListener = new View.OnClickListener() {    public void onClick(View v) {      StringBuilder b = new StringBuilder();      if (!mCIR.hasIrEmitter()) {        mFreqsText.setText("未找到紅外發身器!");        return;      }      // 獲得可用的載波頻率范圍      ConsumerIrManager.CarrierFrequencyRange[] freqs = mCIR          .getCarrierFrequencies();      b.append("IR Carrier Frequencies:/n");// 紅外載波頻率      // 邊里獲取頻率段      for (ConsumerIrManager.CarrierFrequencyRange range : freqs) {        b.append(String.format("  %d - %d/n",            range.getMinFrequency(), range.getMaxFrequency()));      }      mFreqsText.setText(b.toString());// 顯示結果    }  };}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical" ><Button    android:id="@+id/send_button"    android:text="@string/ir_send"    android:layout_width="wrap_content"    android:layout_height="wrap_content"/>  <Button    android:id="@+id/get_freqs_button"    android:text="@string/ir_get_freqs"    android:layout_width="wrap_content"    android:layout_height="wrap_content"/>  <ScrollView    android:id="@+id/freqs_text_scroll"    android:layout_width="match_parent"    android:layout_height="0dp"    android:layout_weight="1" >    <TextView      android:id="@+id/freqs_text"      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:paddingLeft="3dp"      android:paddingRight="3dp" />  </ScrollView></LinearLayout>

更多關于Android相關內容感興趣的讀者可查看本站專題:《Android基本組件用法總結》、《Android視圖View技巧總結》、《Android資源操作技巧匯總》、《Android操作json格式數據技巧總結》、《Android開發入門與進階教程》、《Android編程之activity操作技巧總結》及《Android控件用法總結

希望本文所述對大家Android程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 冀州市| 大同县| 嘉义市| 松原市| 固始县| 烟台市| 观塘区| 平陆县| 新安县| 定安县| 内江市| 昭通市| 德江县| 江北区| 紫金县| 霍州市| 隆子县| 浦北县| 闻喜县| 隆安县| 七台河市| 冀州市| 霍林郭勒市| 中卫市| 莒南县| 盐池县| 贵州省| 望谟县| 卫辉市| 凤台县| 西峡县| 疏附县| 肥乡县| 英吉沙县| 略阳县| 陆河县| 隆林| 喀喇| 巴里| 昌图县| 织金县|