For example, it's possible to press a button in your app and return current accelerometer values?
Or it's possible to get current device orientation (no screen orientation) pressing a button (without persistent listeners)? Thanks!
For example, it's possible to press a button in your app and return current accelerometer values?
Or it's possible to get current device orientation (no screen orientation) pressing a button (without persistent listeners)? Thanks!
Yes that's possible. Just give the corresponding function to the OnClick event of the button that you want to use.
Maybe this tutorial can help you as a starting point.
Edit: Here is an example of how to do it.
First create a button in the layout XML:
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
Then, in the main activity write the following lines in onCreate:
final Button myButton= (Button) findViewById(R.id.button1);
myButton.setOnClickListener(new OnClickListener()
{ public void onClick(View v)
{
// What goes here will be executed after clicking the button
}
});
You need to implement the sensor listener in order to keep a fresh value of the sensors and everytime it changes save a copy into a global variable. Then when clicking the button just call the last value stored.
For orientation you can use the compass instead of the accelerometer but it depends on what you want to do.