I'm creating an app with service that shows Toast
on a long press of the power button
after the app is killed.
How can I implement code that detects the long press of power button?
Here is My Service Class
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
final IntentFilter intentFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
longClick = new LongClick();
registerReceiver(longClick, intentFilter);
// Toast.makeText(getApplicationContext(),"Service Started",Toast.LENGTH_LONG).show();
return START_STICKY;
}
MyRecevier Class
public class LongClick extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS))
{
Toast.makeText(context,"Long Click",Toast.LENGTH_LONG).show();
}
}
}