SENSOR OVERVIEW:
Most Android-powered devices have built-in sensors that measure motion, orientation, and various environmental conditions. These sensors are capable of providing raw data with high precision and accuracy, and are useful if you want to monitor three-dimensional device movement or positioning, or you want to monitor changes in the ambient environment near a device. For example, a game might track readings from a device's gravity sensor to infer complex user gestures and motions, such as tilt, shake, rotation, or swing. Likewise, a weather application might use a device's temperature sensor and humidity sensor to calculate and report the dew point, or a travel application might use the geomagnetic field sensor and accelerometer to report a compass bearing. Read more(Android Developer Tutorial)
HOW TO UNLOCK USING SHAKER APP:
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#80000000"
android:orientation="vertical" >
</LinearLayout>
JAVA:
public class MainActivity extends Activity implements SensorEventListener {
MediaPlayer objPlayer;
SensorManager sm;
long lastTime;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sm = (SensorManager) getSystemService(SENSOR_SERVICE);
lastTime = System.currentTimeMillis();
objPlayer=MediaPlayer.create(this,R.raw.wompwomp);
startService(new Intent(this,LockScreenService.class));
}
@Override
public void onAccuracyChanged(Sensor arg0, int arg1)
{
// TODO Auto-generated method stub
}
@Override
public void onSensorChanged(SensorEvent event)
{
// TODO Auto-generated method stub
if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
{
getAccelerometer(event);
}
}
private void getAccelerometer(SensorEvent event)
{
float[] value = event.values;
float x = value[0];
float y = value[1];
float z = value[2];
float accelationSquareRoot = (x*x + y*y + z*z) / (SensorManager.GRAVITY_EARTH * SensorManager.GRAVITY_EARTH);
long actualTime = System.currentTimeMillis();
if(accelationSquareRoot >= 4)
{
if(actualTime-lastTime < 400)
{
return;
}
lastTime = actualTime;
// Perform your Action Here..
}
}
@Override
protected void onPause()
{
// TODO Auto-generated method stub
super.onPause();
sm.unregisterListener(this);
}
@Override
protected void onResume()
{
// TODO Auto-generated method stub
super.onResume();
sm.registerListener(this,sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),SensorManager.SENSOR_DELAY_NORMAL);
}
}
The Lock screen service and broad cast service are very much similar to the "Gesture Unlock"...
ANDROID MANIFEST:
We have to add permission for the app to do...
HOW TO GET TRANSPARENT SCREEN VIEW OF THE APP:
<application
android:theme="@style/@android:style/Theme.Translucent" > </application>
Next Part will comprise with (TAP TAP UNLOCK - Using Proximity Sensor)...



