android获取加速度传感器的程序问题我现在想获取手机中的加速度传感器的变化值,并将它存入txt文档中,程序应该不难,但是我写出来发现文件穿件不出来,代码如下 :package com.example.getsensorvalue

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/08 15:43:35

android获取加速度传感器的程序问题我现在想获取手机中的加速度传感器的变化值,并将它存入txt文档中,程序应该不难,但是我写出来发现文件穿件不出来,代码如下 :package com.example.getsensorvalue
android获取加速度传感器的程序问题
我现在想获取手机中的加速度传感器的变化值,并将它存入txt文档中,程序应该不难,但是我写出来发现文件穿件不出来,
代码如下 :
package com.example.getsensorvalue;
import java.io.*;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
\x05private SensorManager Sm;
\x05private String a="";
\x05private String b="";
\x05private TextView TV1;
\x05private Button Button1;
\x05private Button Button2;
\x05private File fos=null;
\x05private Writer out=null;
\x05@Override
\x05protected void onCreate(Bundle savedInstanceState) {
\x05\x05super.onCreate(savedInstanceState);
\x05\x05setContentView(R.layout.activity_main);
\x05\x05TV1=(TextView)findViewById(R.id.TV1);
\x05\x05Button1=(Button)findViewById(R.id.Button1);
\x05\x05Button1.setText(R.string.Button1);
\x05\x05Button2=(Button)findViewById(R.id.Button2);
\x05\x05Button2.setText(R.string.Button2);
\x05\x05Sm=(SensorManager)getSystemService(SENSOR_SERVICE);
\x05\x05Sensor Accelerate=Sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
\x05\x05
\x05\x05Sm.registerListener(new SensorEventListener() {
\x05\x05\x05
\x05\x05\x05@Override
\x05\x05\x05public void onSensorChanged(SensorEvent event) {
\x05\x05\x05\x05// TODO Auto-generated method stub
\x05\x05\x05\x05b=b+event.values[0]+" "+event.values[1]+" "+event.values[2]+"\n";
\x05\x05\x05\x05a=event.values[0]+" "+event.values[1]+" "+event.values[2]+"\n";
\x05\x05\x05\x05TV1.setText(a);\x05\x05\x05\x05
\x05\x05\x05}
\x05\x05\x05
\x05\x05\x05@Override
\x05\x05\x05public void onAccuracyChanged(Sensor sensor,int accuracy) {
\x05\x05\x05\x05// TODO Auto-generated method stub
\x05\x05\x05\x05
\x05\x05\x05}
\x05\x05},Accelerate,SensorManager.SENSOR_DELAY_NORMAL);
\x05\x05Button1.setOnClickListener(new OnClickListener() {\x05\x05
\x05\x05\x05@Override
\x05\x05\x05public void onClick(View v) {
\x05\x05\x05\x05// TODO Auto-generated method stub
\x05\x05\x05\x05b="";\x05\x05\x05\x05\x05\x05\x05\x05
\x05\x05\x05}
\x05\x05});
\x05\x05Button2.setOnClickListener(new OnClickListener() {\x05\x05
\x05\x05\x05@Override
\x05\x05\x05public void onClick(View v) {
\x05\x05\x05\x05// TODO Auto-generated method stub
\x05\x05\x05\x05try{
\x05\x05\x05\x05\x05fos=new File(Environment.getExternalStorageDirectory().getPath() +"accelerate.txt");
\x05\x05\x05\x05\x05fos.delete();
\x05\x05\x05\x05\x05fos.createNewFile();
\x05\x05\x05\x05\x05out=new FileWriter(fos);
\x05\x05\x05\x05\x05out.write(b);
\x05\x05\x05\x05\x05out.close();\x05\x05\x05\x05\x05
\x05\x05\x05\x05\x05}
\x05\x05\x05\x05\x05catch(Exception e){
\x05\x05\x05\x05\x05System.out.println(e);
\x05\x05\x05\x05\x05}
\x05\x05\x05}
\x05\x05});
\x05}
\x05@Override
\x05public boolean onCreateOptionsMenu(Menu menu) {
\x05\x05// Inflate the menu; this adds items to the action bar if it is present.
\x05\x05menu.add(0,1,1,R.string.exit);
\x05\x05getMenuInflater().inflate(R.menu.main,menu);
\x05\x05return true;\x05
\x05}
\x05@Override
\x05public boolean onContextItemSelected(MenuItem item) {
\x05\x05// TODO Auto-generated method stub
\x05\x05if(item.getItemId()==1){
\x05\x05\x05finish();
\x05\x05}
\x05\x05return super.onContextItemSelected(item);
\x05}
}

android获取加速度传感器的程序问题我现在想获取手机中的加速度传感器的变化值,并将它存入txt文档中,程序应该不难,但是我写出来发现文件穿件不出来,代码如下 :package com.example.getsensorvalue
fos=new File(Environment.getExternalStorageDirectory().getPath() +"accelerate.txt");
路径错误
应该是fos=new File(Environment.getExternalStorageDirectory().getPath() +"/accelerate.txt");

android获取加速度传感器的程序问题我现在想获取手机中的加速度传感器的变化值,并将它存入txt文档中,程序应该不难,但是我写出来发现文件穿件不出来,代码如下 :package com.example.getsensorvalue 利用加速度传感器测倾斜角android 如何利用速度传感器的三轴加速度求出手机的倾斜角? Android中的加速度传感器能用来测速度吗有对加速度积分的应用吗,或者还可以读出位移 android怎么获取activity的高度 Android如何获取Activity的View? Android 怎么获取经纬度 加速度传感器的应用 android:如何获取当前经纬度的同时获取它的周边一公里的酒店信息 最近看android的传感器,想把手机坐标上的三个方向的加速度转换成相对于地面的加速度相对于地面(正北为Y轴,正东为x轴,天空为z轴 ),求大神帮忙~~~~~ android 求一个简单的使用GPS获取经纬度的代码使用机器上的GPS获取经纬度.求代码 关于三轴加速度传感器的问题请问关于三轴加速度传感器的xyz三个数据代表了什么,换句话说这三组数据有什么用,怎么用? android Gallery画廊出错这是书上的程序,但是在模拟器上出现 程序 has stopped package myandroid.seven;import android.app.Activity;import android.content.Context;//import android.content.Context;import android.graphics.Color;import a 震动传感器和加速度传感器的区别在哪里?用加速度传感器可以测量震动吗? android开发 怎么获取gps经纬度 android 4.4上如何获取经纬度信息 Android 加速度传感器 怎么转换成角度 我得到 了加速度的传感器的三个数值,并且也让它通过句柄显示到了显示屏上,但是现在我想用这三个数值求得设备与水平或垂直的夹角,怎么得到?,有没有 加速度传感器优点欲用加速度传感器采集振动信号,请大家说说用加速度传感器采集争斗信号的优点或加速度传感器的优点!欲用加速度传感器采集振动信号,请大家说说用加速度传感器采集 如何利用android手机的GPS和传感器侧汽车行驶速度,速度的公式是什么