I am trying to show a Toast on the lock screen after a user enters the wrong password 3 times. I am able to verify that the user has failed 3 times through the log console, but would like some message to show on the lock screen so the user knows. I am doing this in a DeviceAdminReceiver. I am able to Toast on a successful password submission, just not a failed one.
import android.app.admin.DeviceAdminReceiver;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
public class AdminReceiver extends DeviceAdminReceiver {
@Override
public void onPasswordFailed(Context ctxt, Intent intent) {
Log.d("LockScreen", "onPasswordFailed");
DevicePolicyManager mgr = (DevicePolicyManager) ctxt.getSystemService(Context.DEVICE_POLICY_SERVICE);
int no = mgr.getCurrentFailedPasswordAttempts();
if (no >= 3) {
Log.d("LockScreen", "Failed 3 times");
//Toast does not show
Toast.makeText(ctxt, R.string.password_failed, Toast.LENGTH_LONG)
.show();
}
}
@Override
public void onPasswordSucceeded(Context ctxt, Intent intent) {
Toast.makeText(ctxt, R.string.password_success, Toast.LENGTH_LONG)
.show();
}
}
The problem is when you show the toast.the lock screen will cover the Toast. because It is not unlocked yet It can be solved by
Create a Transparent Activity. with some custom view to display message. and add below flags to your activity. and just start it and set timer to kill itself in 3 second.
This method allow you to customize your toast : Customizing your toast