gpt4 book ai didi

android - 更新到 2.3.5 后 GYROSCOPE 不工作

转载 作者:太空狗 更新时间:2023-10-29 14:29:20 26 4
gpt4 key购买 nike

我的代码以前可以在2.2上运行,我可以获取陀螺仪数据,但是更新到2.3后,它就不能用了。我还尝试了一个银河播放器,以确保它不是我手机的硬件问题。它对那个也不起作用。有什么建议么?这是代码:

    package my.acc;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;

import android.app.Activity;

import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.ToggleButton;

public class myact extends Activity {

private SensorManager mSensorManager;
Sensor myAcc, myAcc2, myAcc3, myAcc4;
MySensorListener listener, listener2,listener3, listener4;
EditText mEdit;



/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

final Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.activity_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);


// Set up the accelerometer reading
mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
myAcc = mSensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION);
myAcc2 = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
myAcc3 = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
myAcc4 = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);

final ToggleButton togglebutton = (ToggleButton) findViewById(R.id.togglebutton);
mEdit = (EditText)findViewById(R.id.entry);

togglebutton.setOnClickListener(new OnClickListener() {
PrintWriter mCurrentFile = null;
PrintWriter mCurrentFile2 = null;
PrintWriter mCurrentFile3 = null;
PrintWriter mCurrentFile4 = null;


public void onClick(View v) {
// Perform action on clicks
if (togglebutton.isChecked()) {

String strname = spinner.getSelectedItem().toString();
if (strname.equals("Select Activity")){
strname = mEdit.getText().toString();
}
String nameStr = new String("/sdcard/" + strname + "acc" + ".csv");
String nameStr2 = new String("/sdcard/" + strname + "gyr" + ".csv");
String nameStr3 = new String("/sdcard/" + strname + "ori" + ".csv");
String nameStr4 = new String("/sdcard/" + strname + "gra" + ".csv");

File outputFile = new File(nameStr);
File outputFile2 = new File(nameStr2);
File outputFile3 = new File(nameStr3);
File outputFile4 = new File(nameStr4);

try {
mCurrentFile = new PrintWriter(new FileOutputStream(outputFile));
mCurrentFile2 = new PrintWriter(new FileOutputStream(outputFile2));
mCurrentFile3 = new PrintWriter(new FileOutputStream(outputFile3));
mCurrentFile4 = new PrintWriter(new FileOutputStream(outputFile4));

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

mSensorManager.registerListener(listener = new MySensorListener(mCurrentFile), myAcc , SensorManager.SENSOR_DELAY_UI);
mSensorManager.registerListener(listener2 = new MySensorListener(mCurrentFile2), myAcc2 , SensorManager.SENSOR_DELAY_UI);
mSensorManager.registerListener(listener3 = new MySensorListener(mCurrentFile3), myAcc3 , SensorManager.SENSOR_DELAY_UI);
mSensorManager.registerListener(listener4 = new MySensorListener(mCurrentFile4), myAcc4 , SensorManager.SENSOR_DELAY_UI);

//mSensorManager.registerListener(listener, myAcc2 , SensorManager.SENSOR_DELAY_FASTEST);

} else {


mSensorManager.unregisterListener(listener, myAcc);
mSensorManager.unregisterListener(listener2, myAcc2);
mSensorManager.unregisterListener(listener3, myAcc3);
mSensorManager.unregisterListener(listener4, myAcc4);
mCurrentFile.close();
mCurrentFile2.close();
mCurrentFile3.close();
mCurrentFile4.close();




}
}
});
}
}
package my.acc;

import java.io.PrintWriter;

import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;

public class MySensorListener implements SensorEventListener {

String comma = new String(",");
private PrintWriter mCurrentFile;

public MySensorListener( PrintWriter mCurrentFile){
//Creating a file to print the data into

this.mCurrentFile = mCurrentFile;

}


public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO Auto-generated method stub

}



public void onSensorChanged(SensorEvent event) {

StringBuffer buff = new StringBuffer();

buff.append(String.valueOf(event.sensor.getName()));
buff.append(comma);


buff.append(String.valueOf(event.timestamp));


buff.append(comma);

buff.append(String.valueOf(event.values[0]));
buff.append(comma);
buff.append(String.valueOf(event.values[1]));
buff.append(comma);
buff.append(String.valueOf(event.values[2]));

mCurrentFile.println(buff.toString());
mCurrentFile.flush();


}


}

我什至向谷歌报告了一个错误,这是他们的回应:

those aren't Google devices, so you'll have to talk to Samsung

最佳答案

我不确定这是否有帮助,但这似乎与您的问题有关:陀螺仪无法闪烁 ROM。您可以查看 (Galaxy S2 - Gyro & Compass not working) 并尝试运行建议的测试。

关于android - 更新到 2.3.5 后 GYROSCOPE 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8304472/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com