我想创建一个applock应用程序,用户可以在其中密码保护应用程序。我将使用设备管理员,但如果恶意用户在解锁时访问手机,他可以从设置中禁用它并轻松卸载。
一款名为“applock'有一个高级保护应用程序,允许他们在禁用设备管理员之前请求密码。
我如何提供此功能?我想使用手机现有的密码。
答案 0 :(得分:0)
In your DeviceAdminReceiver class, override this method:
public CharSequence onDisableRequested(Context context, Intent intent);
Here you should be able to lock the device immediately (since you will still have admin privileges). Once the user unlocks the device, they will be able to hit the ok button to deactivate your app. This would look something like this:
@Override
public CharSequence onDisableRequested(Context context, Intent intent) {
DevicePolicyManager dpm = (DevicePolicyManager)
context.getApplicationContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
dpm.lockNow();
Log.d(TAG, "Disable requested");
return "Are you sure??"; //This gets displayed in an alert dialog, but will only be visible after the user unlocks the screen
}
I realize this isn't exactly what you're asking, but the end result is similar. The alternate solution I've seen reference elsewhere is to implement a Service with listens for running applications/Activities (like AppBlock does). If it sees that the Activity to disable device administrator is running, it pops up a new Activity to request a password.
I suspect that would work, but I haven't coded it myself. Additionally, I'm not sure how you would have that Activity request the device password as opposed to some internal password for your app.
Hope that helps!