2017-03-19 16 views
0

管理者権限を取得すると正常に動作します。問題はDeviceAdminReceiverが呼び出されないことだけです。失敗したパスワードの数をチェックしようとしています。DeviceAdminReceiverが呼び出されることはありません

public class MyAdminReceiver extends DeviceAdminReceiver { 

void showToast(Context context, CharSequence msg) { 
    Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); 
} 

@Override 
public void onPasswordFailed(Context context, Intent intent) { 
    showToast(context, "Sample Device Admin: pw failed"); 
    Log.d("Hello", "onPasswordFailed"); 
    DevicePolicyManager mgr = (DevicePolicyManager)context.getSystemService(Context.DEVICE_POLICY_SERVICE); 
    int no = mgr.getCurrentFailedPasswordAttempts(); 


    if (no >= 3) { 
     showToast(context, "3 failure"); 
     mgr.resetPassword("111111", DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY); 
     //mgr.lockNow(); 
    } 
} 


@Override 
public void onEnabled(Context context, Intent intent) { 
    showToast(context, "Sample Device Admin: enabled"); 
} 

@Override 
public CharSequence onDisableRequested(Context context, Intent intent) { 
    return "This is an optional message to warn the user about disabling."; 
} 

@Override 
public void onDisabled(Context context, Intent intent) { 
    showToast(context, "Sample Device Admin: disabled"); 
} 

@Override 
public void onPasswordChanged(Context context, Intent intent) { 
    showToast(context, "Sample Device Admin: pw changed"); 
} 



@Override 
public void onPasswordSucceeded(Context context, Intent intent) { 
    showToast(context, "Sample Device Admin: pw succeeded"); 
} 

} 

私はまた私のマニフェスト

<receiver 
     android:name=".MyAdminReceiver" 
     android:permission="android.permission.BIND_DEVICE_ADMIN"> 
     <meta-data android:name="android.app.device_admin" 
      android:resource="@xml/device_admin" /> 
     <intent-filter> 
      <action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/> 
     </intent-filter> 
    </receiver> 

とdevice_admin

<?xml version="1.0" encoding="utf-8"?> 
<device-admin xmlns:android="http://schemas.android.com/apk/res/android"> 
    <uses-policies> 
     <limit-password /> 
     <watch-login /> 
     <reset-password /> 
     <force-lock /> 
     <wipe-data /> 
     <expire-password /> 
     <encrypted-storage /> 
     <disable-camera /> 
    </uses-policies> 
</device-admin> 

でそれを宣言した誰も私にその原因が何であるかの助言を与えることはできますか? ありがとうございます。

+0

'のres/XML/device_admin'の内容は何ですか? – CommonsWare

+0

<?xml version = "1.0" encoding = "utf-8"?> <リミットパスワード/> <時計ログイン/> <リセットパスワード/> <フォース・ロック/> <期限切れとパスワード/> <暗号化されたストレージ/> <無効にし、カメラ/>

+0

これは正常です(管理機能の*ロット*を求めている以外は...)。最後に[この本のサンプル](https://github.com/commonsguy/cw-omnibus/tree/master/DeviceAdmin/PasswordEnforcer)を試してみましたが、うまくいきました。試してみるか、あなたの実装と心の間に顕著な違いがあるかどうかを確認してください。 – CommonsWare

答えて

0

たぶん

<intent-filter> 
    <action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/> 
    <action android:name="android.app.action.ACTION_PASSWORD_FAILED"/> 
    <action android:name="android.app.action.ACTION_PASSWORD_SUCCEEDED"/> 
</intent-filter> 

<intent-filter> 
    <action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/> 
</intent-filter> 

を変更

関連する問題