如何获得的图案或密码写错误信息 [英] How get message that the pattern or the password written wrong
问题描述
我想,计数,甚至获取密码或移动的模式写入错误的功能?
i want a function that count or even get that the password or the pattern of the mobile is written wrong ?
public int number_of_times ()
}
返回时间;
}
}
return times;
}
推荐答案
如果您使用设备管理API这是唯一可能的。具体而言,您需要:
This is only possible if you use the device administration APIs. Specifically, you need:
-
在
DeviceAdminReceiver
的子类,适当的清单,在那里你会找到有关的密码失效注册
a
DeviceAdminReceiver
subclass, appropriately registered in the manifest, where you would find out about password failures
设备管理元数据,说明你想被告知有关设备管理的失败
device admin metadata, indicating that you wanted to be informed about device admin failures
一个用户界面,帮助用户进入设置程序,使您的应用程序作为设备管理员
a UI that helps the user go into the Settings app and enable your app as a device administrator
这证明了这一切,因为部分样本项目稍大样本还设置密码的质量要求。
This sample project demonstrates all of that, as part of a slightly larger sample that also sets password quality requirements.
值得注意的是,被告知我的 AdminReceiver
的清单中要求的元素有关的密码失效,通过包括 ACTION_PASSWORD_FAILED
在行动我的<意向滤光器>
:
Of note, my AdminReceiver
's element in the manifest requests to be informed about password failures, by including the ACTION_PASSWORD_FAILED
action in my <intent-filter>
:
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
<action android:name="android.app.action.ACTION_PASSWORD_CHANGED"/>
<action android:name="android.app.action.ACTION_PASSWORD_FAILED"/>
<action android:name="android.app.action.ACTION_PASSWORD_SUCCEEDED"/>
</intent-filter>
</receiver>
另外,我的设备管理元数据( RES / XML / device_admin.xml
)包括&LT;钟表登陆/&GT;
政策:
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<limit-password/>
<watch-login/>
</uses-policies>
</device-admin>
另外,我的 AdminReceiver
是 DeviceAdminReceiver
的子类,覆盖 onPasswordFailed()
,以了解失败的:
In addition, my AdminReceiver
is a subclass of DeviceAdminReceiver
and overrides onPasswordFailed()
, to find out about failures:
/***
Copyright (c) 2013 CommonsWare, LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License.
From _The Busy Coder's Guide to Android Development_
https://commonsware.com/Android
*/
package com.commonsware.android.pwenforce;
import android.app.admin.DeviceAdminReceiver;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class AdminReceiver extends DeviceAdminReceiver {
@Override
public void onEnabled(Context ctxt, Intent intent) {
ComponentName cn=new ComponentName(ctxt, AdminReceiver.class);
DevicePolicyManager mgr=
(DevicePolicyManager)ctxt.getSystemService(Context.DEVICE_POLICY_SERVICE);
mgr.setPasswordQuality(cn,
DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC);
onPasswordChanged(ctxt, intent);
}
@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, 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();
}
}
这篇关于如何获得的图案或密码写错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!