Here is the code snippet from the DeviceAdminReceiver subclass implemented by me: -
public void onDisabled(Context context, Intent intent)
{
super.onDisabled(context, intent);
AntiTheftApplicationContext.setApplicationContext(
context.getApplicationContext());
final Context applicationContext = AntiTheftApplicationContext.
getApplicationContext();
Thread thread = new Thread(new Runnable()
{
@Override
public void run()
{
applicationContext.stopService(new Intent(applicationContext, AuthenticationWakeupCallReceiver.class));
applicationContext.startService(new Intent(applicationContext, AuthenticationWakeupCallReceiver.class));
}
});
thread.start();
while(AntiTheftUtil.isMyServiceRunning(
AuthenticationWakeupCallReceiver.class.getName()))
{
try
{
Thread.sleep(20000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
Authentication: WakeupCallReceiver triggers another action, i.e. PostStartupAuthenticationActivity: -
if(!PostStartupAuthenticationActivity.isActivityRunning())
{
Intent intent = new Intent(context,XYZ.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
XYZ activity contains an EditText, which is defined in the layout file as follows: -
<EditText
android:id="@+id/re_enter_authentication_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="enter authentication code"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
The processing for EditText is done in my code as follows: -
final EditText dataEnteredEditText = (EditText)findViewById(R.id.re_enter_authentication_code);
TextWatcher watcher = new TextWatcher()
{
int countAttempts = 0;
@Override
public void onTextChanged(CharSequence enteredText, int start, int before, int count)
{
String value = enteredText.toString();
if(value.length() >= authenticationCode.length() && !value.equals(authenticationCode))
{
dataEnteredEditText.setError("Invalid Code!!!");
dataEnteredEditText.setText(AntiTheftConstants.EMPTY_STRING);
countAttempts++;
if(countAttempts == 3)
{
SharedPreferences.Editor editor = sharedPref.edit();
editor.putBoolean(AntiTheftConstants.USER_AUTHENTICATION_STATUS, false);
editor.commit();
startProcessForAuthenticationFailure();
finish();
}
else if(value.equals(authenticationCode))
{
mIsCorrectPasswordEntered = true;
stopService(new Intent(AntiTheftApplicationContext.getApplicationContext(), AuthenticationWakeupCallReceiver.class));
stopService(new Intent(AntiTheftApplicationContext.getApplicationContext(), AuthenticationWakeupCallReceiver.class));
notifySuccessfulAuthentication();
}
}
}
Problem 1: - But when XYZ is called from AuthenticationWakeupCallReceiver, the EditText defined in the XYZ action stops accepting numbers. When I enter simple letters, it is accepted, but when I enter numbers, it is not accepted. I get the following warning message: - "getTextBeforeCursor on inactive InputConnection".
2: -
. DeviceAdminReceiver . . , . onDisabled DeviceAdminReceiver .