8

セキュリティ アプリを作成していますが、ユーザーが間違ったパスワードを入力しているかどうかを知る必要があります。ユーザーの電話がパターンロックシステムによってロックされ、残念ながらユーザーがパターンパスワードを忘れたとします。ユーザーが間違ったパターンを 5 回入力すると、30 秒間のペナルティが発生します。そのペナルティ イベントをキャッチする必要があります。私のアプリでは、これが来ても(ユーザーの安全のために)いくつかのタスクを実行する必要があります。私を助けてください、

4

3 に答える 3

2

APIレベル22のAndroidスタジオでも同じことをしています。しかし、何も起こっていません。エラーが表示されます-「com.example.sourav.myfirstapp DEVICE SHELL COMMANDをインストールしています: pm install -r "/data/local/tmp/com.example.sourav.myfirstapp" pkg: /data/local/tmp/com.example .sourav.myfirstapp の失敗 [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED]"

これが私のプロジェクトの詳細です-管理者レシーバーの主な活動-

public class AdminReceiver extends DeviceAdminReceiver {

@Override
public void onPasswordChanged(Context ctxt, Intent intent) {
    DevicePolicyManager mgr=
            (DevicePolicyManager)ctxt.getSystemService(Context.DEVICE_POLICY_SERVICE);
    int msgId;

    if (mgr.isActivePasswordSufficient()) {
        msgId=R.string.compliant;
    }
    else msgId = R.string.not_compliant;

    Toast.makeText(ctxt, msgId, Toast.LENGTH_LONG).show();
}

@Override
public void onPasswordFailed(Context ctxt, Intent intent) {
    Toast.makeText(ctxt, "u will never break!", Toast.LENGTH_LONG)
            .show();
    String tag="tag";
    Log.v(tag,"this massage from error" );
}

@Override
public void onPasswordSucceeded(Context ctxt, Intent intent) {
    Toast.makeText(ctxt, "good u enterd", Toast.LENGTH_LONG)
            .show();
    String tag="tag";
    Log.v(tag, "this massage from success");
}
}

マニフェスト-

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.example.sourav.myfirstapp" >
 


 <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >

    <receiver
        android:name="AdminReceiver"
        android:permission="android.permission.BIND_DEVICE_ADMIN">
        <meta-data
            android:name="android.app.device_admin"
            />

        <intent-filter>

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

 </manifest>




Metadata-
 
 <device-admin xmlns:android="http://schemas.android.com/apk/res/android">

   <uses-policies>
    <limit-password/>

    <watch-login/>
</uses-policies>
于 2015-10-17T03:56:27.757 に答える
1
  1. 最初のステップは、アプリにDEVICE_ADMINユーザー権限を付与することです。

  2. を拡張する独自のクラスを作成しますDeviceAdminReceiver。このためには、インポートする必要がありますimport android.app.admin.DeviceAdminReceiver;

  3. あなたの場合のメソッドを次のようにオーバーライドします。

    @Override
    public void onPasswordFailed(Context context, Intent intent) {
        Log.d("Hello", "onPasswordFailed");
    }
    @Override
    public void onPasswordSucceeded(Context context, Intent intent) {
        Log.d("Hello", "onPasswordSucceeded");
    }
    
于 2015-06-05T07:42:57.030 に答える