編輯:關於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;
}
}
Creating Lists and Cards 創建列表和卡片,
Creating Lists and Cards 創建列表和卡片,To create complex lists and cards with material des
Android項目開發實戰之使用Fragment和FragmentTabHost搭建底部菜單(一)
Android項目開發實戰之使用Fragment和FragmentTabHost搭建底部菜單(一) 學習在於實用,只有把自己學到的東西真正的融入到我們的開
Android面試准備 第二天 第五例 數據存儲
Android面試准備 第二天 第五例 數據存儲 5、Activity用SharedPreferences保存數據,大小有木有限制? 個人理解:SharedPrefere
釋放Android的函數式能量(I):Kotlin語言的Lambda表達式,kotlinlambda
釋放Android的函數式能量(I):Kotlin語言的Lambda表達式,kotlinlambda原文標題:Unleash functional power on An