Turn off screen programmatically when face is close the screen on Android

I found solution by disassembling one very famous VoIP application. This activity after pressing button1 will disable screen and hardware keys when you close sensors. After pressing button2 this function will be switched off. Also, this function required permission: <uses-permission android:name=”android.permission.WAKE_LOCK” /> Activity. Try it. public class MainActivity extends Activity { private Button button1; private … Read more

What is the alternative to android orientation sensor?

There is no actual “orientation” sensor – this is (was) actually a composite sensor, generated from a combination of the accelerometer and the magnometer. From http://developer.android.com/reference/android/hardware/SensorEvent.html “This sensor type exists for legacy reasons, please use getRotationMatrix() in conjunction with remapCoordinateSystem() and getOrientation() to compute these values instead.” public class OrientationTestActivity extends Activity implements SensorEventListener { … Read more

How to use Accelerometer to measure distance for Android Application Development

You get position by integrating the linear acceleration twice but the error is horrible. It is useless in practice. Here is an explanation why (Google Tech Talk) at 23:20. I highly recommend this video. Similar questions: track small movements of iphone with no GPS What is the real world accuracy of phone accelerometers when used … Read more

My Algorithm to Calculate Position of Smartphone – GPS and Sensors

As some of you mentioned you got the equations wrong but that is just a part of the error. Newton – D’Alembert physics for non relativistic speeds dictates this: // init values double ax=0.0,ay=0.0,az=0.0; // acceleration [m/s^2] double vx=0.0,vy=0.0,vz=0.0; // velocity [m/s] double x=0.0, y=0.0, z=0.0; // position [m] // iteration inside some timer (dt … Read more

How do I find out if the GPS of an Android device is enabled

Best way seems to be the following: final LocationManager manager = (LocationManager) getSystemService( Context.LOCATION_SERVICE ); if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) { buildAlertMessageNoGps(); } private void buildAlertMessageNoGps() { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(“Your GPS seems to be disabled, do you want to enable it?”) .setCancelable(false) .setPositiveButton(“Yes”, new DialogInterface.OnClickListener() { public void onClick(@SuppressWarnings(“unused”) final … Read more