Mon code fonctionnait sur la version 2.2, et j'arrivais à obtenir les données du gyroscope, mais après la mise à jour vers la version 2.3, ça ne fonctionne plus. J'ai également essayé sur un galaxy player pour m'assurer que ce n'est pas un problème matériel avec mon téléphone. Ça n'a pas fonctionné non plus. Des suggestions ? Voici le code :
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 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();
}
}
});
}
}
J'ai même signalé un bug à Google, voici leur réponse :
ce ne sont pas des appareils Google, donc vous devrez parler à Samsung