Note : Phone will not detect any touch event on screen when it is in standby mode or sleeping mode. So the only option is to get events from any hardware button via register intent action in Broadcast Receiver.
You can generate SOS by hooking power button. Register a Broadcast Receiver which is initiated when power button is clicked.
Now in onReceive()
method of the Receiver do what you want. Below Code For Broadcast receiver Class :
public class PowerHookReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
Log.v("#@%@%#", "Power button is pressed.");
Toast.makeText(arg0, "power button clicked",Toast.LENGTH_LONG).show();
//perform what you want here
}
}
Register this receiver in Manifest :
<receiver android:name="com.PowerHookReceiver">
<intent-filter>
<action android:name="android.intent.action.SCREEN_OFF"></action>
<action android:name="android.intent.action.SCREEN_ON"></action>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED"></action>
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"></action>
<action android:name="android.intent.action.ACTION_SHUTDOWN"></action>
</intent-filter>
</receiver>
Now perform your task in onReceive()
method of the Receiver.