天天看点

MTK 6735Gsensor数据采样(第一次用app采样)

1、addView

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:paddingBottom="@dimen/activity_vertical_margin"

    android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    tools:context=".MainActivity" >

    <TextView

        android:id="@+id/textView1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignParentLeft="true"

        android:layout_marginLeft="36dp"

        android:text="@string/hello_world" />

    <TextView

        android:id="@+id/tv_two"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_alignParentRight="true"

        android:layout_below="@+id/textView1" />

</RelativeLayout>

2 使用代码,

package com.example.gsensorapp;

import android.app.Activity;

import android.hardware.Sensor;

import android.hardware.SensorEvent;

import android.hardware.SensorEventListener;

import android.hardware.SensorManager;

import android.os.Bundle;

import android.widget.TextView;

 public class MainActivity  extends Activity implements SensorEventListener {

     private SensorManager mSensorManager;

     private Sensor mAccelerometer;

     private TextView mTextView;

     private TextView mTextViewHello;

     @Override

     protected void onCreate(Bundle savedInstanceState) {

         super.onCreate(savedInstanceState);

         setContentView(R.layout.activity_main);

         mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE); //传感器管理器获取到 SensorManager 的实例

         mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);  //获取传感器类型

         mTextView =(TextView)this.findViewById(R.id.tv_two); //获取Text view

         mTextViewHello =(TextView)this.findViewById(R.id.textView1); 

     }

     protected void onResume() { //加速度传感器注册监听器

         super.onResume();

mSensorManager.registerListener((SensorEventListener) this, mAccelerometer,SensorManager.SENSOR_DELAY_NORMAL);

         mTextViewHello.setText("Accelerometer test hello"); //在模拟器上测试

     }

     protected void onPause() { //取消注册监听器

         super.onPause();

         mSensorManager.unregisterListener((SensorEventListener) this);

     }

     public void onAccuracyChanged(Sensor sensor, int accuracy) { //传感器的精度发生变化时就会调用

     }

     public void onSensorChanged(SensorEvent event) { //当传感器监测到的数值发生变化时就会调用

            float[] values = event.values;

            //TextView mTextView=new TextView(this);

            mTextView.setText("Accelerometer:" + values[0] + ";" + values[1] + ";" + values[2]); //显示

     }

 }

3:生成的apk放项目下编译加签名。

include $(CLEAR_VARS)

# Module name should match apk name to be installed

LOCAL_MODULE := Gsensorapp

LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := $(LOCAL_MODULE).apk

LOCAL_MODULE_CLASS := APPS

LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)

LOCAL_CERTIFICATE := PRESIGNED

include $(BUILD_PREBUILT)

adb push system/app/目录中

4:图片效果

MTK 6735Gsensor数据采样(第一次用app采样)

5:直接用eclipse中DDMS连接硬件设备,我连接的是我我自己编译的系统。

然后用Screen Capture 功能拍照