I am developing an SOS android app. I want to detect a gesture (for example several touches on screen) if the phone is in mode sleep/standby, and start a send of help request (for example send a sms). How can I detect this gesture? Someone that can help me? Thank you
---SOLUTION---- I found the solution here and this is my code:
1)in the main activity
getApplicationContext().startService(new Intent(this, UpdateService.class));
2)I create a service
public class UpdateService extends Service {
@Override
public void onCreate() {
super.onCreate();
// register receiver that handles screen on and screen off logic
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
BroadcastReceiver mReceiver = new PowerHookReceiver();
registerReceiver(mReceiver, filter);
}
@Override
public void onStart(Intent intent, int startId) {
boolean screenOn = intent.getBooleanExtra("screen_state", false);
if (!screenOn) {
// your code
} else {
// your code
}
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}}
3) I create a PowerHookReceiver();
public class PowerHookReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, UpdateService.class);
context.startService(i);
//do what you want
}}
4) The manifest
<uses-permission android:name="android.permission.PREVENT_POWER_KEY" />
<receiver android:name=".PowerHookReceiver" >
</receiver>
<service android:name=".UpdateService" />
I hope it is usefull =)