I want to do as below:
User press hard unlock button. After pressing unlock button my activity is start. After close my activity using close button on screen user prompt to enter pattern lock(or pin lock). after enter right pattern lock home screen appear.
I want below scenario:
press power/unlock button -> start my activity -> click close button of activity -> prompt to enter pattern for unlock -> enter pattern -> display home screen
Currently Done as below:
Using Broadcast Receiver of ACTION_USER_PRESENT
I got the activity after user enter pattern & device is unlock
Using Broadcast Receiver of ACTION_SCREEN_ON
, I got the msg on log after unlock button press but activity is start after user enter pattern & device is unlock.
I try using Broadcast Receiver to receive event of ACTION_SCREEN_ON
and ACTION_USER_PRESENT
.
My Code is as Below:
Broadcast Receiver -
public class BrodcastReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Log.d("receiver", "main");
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF))
{
// do whatever you need to do here
Log.d("receiver", "screen off");
}
else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON))
{
// and do whatever you need to do here
Log.d("receiver", "screen on");
context.startActivity(new Intent(context,
unlock_image.class)
.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
Log.d("receiver", "aft activity");
}
else if (intent.getAction().equals(Intent.ACTION_USER_PRESENT))
{
Log.d("receiver", "unlock");
context.startActivity(new Intent(context,
unlock_image.class)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
}
Register Broadcast Listner -
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_USER_PRESENT);
BroadcastReceiver mReceiver = new BrodcastReceiver();
registerReceiver(mReceiver, filter);
I try lots but I can't get what I want. Any help is appreciated if any one have idea, How to get expected result as I want.