I am using Android's Administration API and have a DeviceAdminReceiver, and override the following functions:
@Override
public void onEnabled(Context context, Intent intent)
{
System.out.println("Admin On======================");
}
@Override
public void onDisabled(Context context, Intent intent)
{
System.out.println("Admin Off======================");
}
@Override
public void onPasswordFailed(Context context, Intent intent)
{
System.out.println("PW Bad============================");
}
@Override
public void onPasswordSucceeded(Context context, Intent intent)
{
System.out.println("PW Good===========================");
}
@Override
public void onPasswordChanged(Context context, Intent intent)
{
System.out.println("Changed PW=======================");
}
On enabled, Disabled, and PW changed work, however password failed and succeeded do not. Strangely, they randomly work once in a while and then stop working. Is there anything wrong with my code, or could this be an API problem?
The receiver in AndroidMaifest
<receiver android:name="AdminReciever"
android:label="Administration"
android:permission="android.permission.BIND_DEVICE_ADMIN" android:enabled="true">
<meta-data android:name="android.app.device_admin"
android:resource="@xml/adminpolicies" />
<intent-filter>
<action android:name="android.app.action.ACTION_PASSWORD_SUCCEEDED"/>
<action android:name="android.app.action.ACTION_PASSWORD_FAILED"></action>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED"></action>
<action android:name="android.app.action.ACTION_PASSWORD_CHANGED"></action>
</intent-filter>
</receiver>
FIXED
Found out the problem, it seems this wasn't documented. I had set a minimum password length with dpm.setPasswordMinimumLength(). The password entry activity does not fire a PASSWORD_FAILED intent if the password entered is less then the minimum length. Also PASSWORD_SUCCEEDED only fires if a bad password (PASSWORD_FAILED fired) was entered before the successful one. So two successful passwords in a row will not fire the second intent.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…