Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 關於android開發 >> Android開發教程 錄制多媒體實例

Android開發教程 錄制多媒體實例

編輯:關於android開發

  Android開發教程,今天我們來看下IBM的Android開發人員的關於安卓開發中錄制多媒體的實例代碼:

  /*

  *

  * IBMEyes.java

  * sample code for IBM Developerworks Article

  * Author: W. Frank Ableson

  *

  */

  package com.msi.ibm.eyes;

  import android.app.Activity;

  import android.os.Bundle;

  import android.util.Log;

  import android.widget.TextView;

  import android.hardware.SensorManager;

  import android.hardware.SensorListener;

  public class IBMEyes extends Activity implements SensorListener {

  final String tag = "IBMEyes";

  SensorManager sm = null;

  TextView xViewA = null;

  TextView yViewA = null;

  TextView zViewA = null;

  TextView xViewO = null;

  TextView yViewO = null;

  TextView zViewO = null;

  /** Called when the activity is first created. */

  @Override

  public void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  sm = (SensorManager) getSystemService(SENSOR_SERVICE);

  setContentView(R.layout.main);

  xViewA = (TextView) findViewById(R.id.xbox);

  yViewA = (TextView) findViewById(R.id.ybox);

  zViewA = (TextView) findViewById(R.id.zbox);

  xViewO = (TextView) findViewById(R.id.xboxo);

  yViewO = (TextView) findViewById(R.id.yboxo);

  zViewO = (TextView) findViewById(R.id.zboxo);

  }

  public void onSensorChanged(int sensor, float[] values) {

  synchronized (this) {

  Log.d(tag, "onSensorChanged: " + sensor + ", x: " + values[0] + ", y: " + values[1] + ", z: " + values[2]);

  if (sensor == SensorManager.SENSOR_ORIENTATION) {

  xViewO.setText("Orientation X: " + values[0]);

  yViewO.setText("Orientation Y: " + values[1]);

  zViewO.setText("Orientation Z: " + values[2]);

  }

  if (sensor == SensorManager.SENSOR_ACCELEROMETER) {

  xViewA.setText("Accel X: " + values[0]);

  yViewA.setText("Accel Y: " + values[1]);

  zViewA.setText("Accel Z: " + values[2]);

  }

  }

  }

  public void onAccuracyChanged(int sensor, int accuracy) {

  Log.d(tag,"onAccuracyChanged: " + sensor + ", accuracy: " + accuracy);

  }

  @Override

  protected void onResume() {

  super.onResume();

  sm.registerListener(this,

  SensorManager.SENSOR_ORIENTATION |

  SensorManager.SENSOR_ACCELEROMETER,

  SensorManager.SENSOR_DELAY_NORMAL);

  }

  @Override

  protected void onStop() {

  sm.unregisterListener(this);

  super.onStop();

  }

  }

  R.java文件:

  /* AUTO-GENERATED FILE. DO NOT MODIFY.

  *

  * This class was automatically generated by the

  * aapt tool from the resource data it found. It

  * should not be modified by hand.

  */

  package com.msi.ibm.eyes;

  public final class R {

  public static final class attr {

  }

  public static final class drawable {

  public static final int icon=0x7f020000;

  }

  public static final class id {

  public static final int xbox=0x7f050000;

  public static final int xboxo=0x7f050003;

  public static final int ybox=0x7f050001;

  public static final int yboxo=0x7f050004;

  public static final int zbox=0x7f050002;

  public static final int zboxo=0x7f050005;

  }

  public static final class layout {

  public static final int main=0x7f030000;

  }

  public static final class string {

  public static final int app_name=0x7f040001;

  public static final int hello=0x7f040000;

  }

  }

 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved