Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to write sensor data into file android studio

public class Main extends Activity implements SensorEventListener {

private SensorManager mSensorManager;
private Sensor mAccelerometer;
private FileWriter writer;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activiy_main);
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
}

public void onStartClick(View view) {
    mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
}

public void onStopClick(View view) {
    mSensorManager.unregisterListener(this);
}
protected void onResume() {
    super.onResume();
    writer = new FileWriter("myfile.txt",true);
}

protected void onPause() {
    super.onPause();

    if(writer != null) {
       writer.close();
    }
}

@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {

}

@Override
public void onSensorChanged(SensorEvent event) {

    float x = event.values[0];
    float y = event.values[1];
    float z = event.values[2];
    writer.write(x+","+y+","+z+"
");

 }
}
Comment

PREVIOUS NEXT
Code Example
Java :: spigot run code asynhronously 
Java :: java string to char array 
Java :: how to change a bukkit chat format 
Java :: how to parse json array in java 
Java :: appcompatdelegate.setdefaultnightmode(appcompatdelegate.mode_night_yes) not working 
Java :: sort array<entry float android studio 
Java :: Bukkit debug message 
Java :: plus one leetcode 
Java :: take string until / 
Java :: how to write custom message for repeat password in joi 
Java :: lakshya 
Java :: processing load font from file 
Java :: How to find the power of a number efficiently in Java? 
Java :: print arraylist java 
Java :: convert char to string java 
Java :: spring data rest format time 
Java :: how to find smallest number in array java 
Java :: close searchview android java 
Java :: java iterable to list 
Java :: java public static void main 
Java :: Rxjava dependencies 
Java :: assert system.out.println 
Java :: java http request post 
Java :: short java 
Java :: java instant to localdatetime 
Java :: add certificate to java truststore 
Java :: java list to set 
Java :: what is final in java 
Java :: get file dimension java 
Java :: print to console in java 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =