Android中设备管理员的用途是什么? [英] What is a use of device administrator in android?

查看:401
本文介绍了Android中设备管理员的用途是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对设备管理员api有疑问/疑问,使用此API可以通过任何方式限制我的应用程序的取消安装,可能是通过使用密码。

I have doubt/question about device administrator api, using this API can I limit my application from uninstillation by any way, may be by using password.

请告诉我究竟是什么设备管理员api?如何在应用程序中使用它们?以及如何确定需要设置哪些策略?

Please tell me what exactly device administrator api does? How I can used them in my application? And how I can decide which Policies I need to set?

在这种混乱中请帮助我。

Please help me in this confusion.

推荐答案

设备管理员API是在系统级别提供设备管理功能的API。这些API使您可以创建具有安全意识的应用程序。

Device Administrator API is an API that provides device administration features at the system level. These APIs allow you to create security-aware applications. It is used to make your application uninstall from the device or to capture a picture by using a camera when the screen is a lock.

设备管理API支持诸如以下的策略:它用于使应用程序从设备上卸载或通过使用摄像头捕获图片。 ,

1.)启用密码-要求设备要求输入PIN或密码。

The Device Administration API supports the policies like,
1.) Password enabled - Requires that devices ask for PIN or passwords.

2。)最小密码长度-设置密码所需的字符数。例如,您可以要求PIN或密码至少包含六个字符。

2.) Minimum password length - Set the required number of characters for the password. For example, you can require PIN or passwords to have at least six characters.

3.)需要字母数字密码-要求密码包含字母和数字。它们可能包含符号字符。

3.) Alphanumeric password required - Requires that passwords have a combination of letters and numbers. They may include symbolic characters.

4.)需要复杂的密码-要求密码必须至少包含字母,数字和特殊符号。在Android 3.0中引入。

4.) Complex password required - Requires that passwords must contain at least a letter, a numerical digit, and a special symbol. Introduced in Android 3.0.

5。)密码中要求的最少字母-所有管理员或特定管理员密码中要求的最小字母数量。在Android 3.0中引入。

5.) Minimum letters required in password - The minimum number of letters required in the password for all admins or a particular one. Introduced in Android 3.0.

6.)密码中要求的最小小写字母-所有管理员或特定管理员密码中要求的最小小写字母数量。在Android 3.0中引入。

6.) Minimum lowercase letters required in password - The minimum number of lowercase letters required in the password for all admins or a particular one. Introduced in Android 3.0.

7.)密码过期超时-密码过期时,表示为从设备管理员设置过期超时起的毫秒数。在Android 3.0中引入。

7.) Password expiration timeout - When the password will expire, expressed as a delta in milliseconds from when a device admin sets the expiration timeout. Introduced in Android 3.0.

8.)尝试输入密码的最大次数-指定用户在设备擦除其数据之前可以输入错误密码的次数。设备管理API还允许管理员将设备远程重置为出厂默认值。如果设备丢失或被盗,这可以保护数据。

8.) Maximum failed password attempts - Specifies how many times a user can enter the wrong password before the device wipes its data. The Device Administration API also allows administrators to remotely reset the device to factory defaults. This secures data in case the device is lost or stolen.

9.)最大不活动时间锁定-设置自用户最后一次触摸屏幕或在设备锁定屏幕之前按下按钮以来的时间长度。发生这种情况时,用户需要再次输入其PIN或密码,然后才能使用其设备并访问数据。该值可以在1到60分钟之间。

9.) Maximum inactivity time lock - Sets the length of time since the user last touched the screen or pressed a button before the device locks the screen. When this happens, users need to enter their PIN or passwords again before they can use their devices and access data. The value can be between 1 and 60 minutes.

10。)禁用摄像头-指定应禁用摄像头。请注意,这并不一定要永久禁用。可以根据上下文,时间等动态启用/禁用摄像机。在Android 4.0中引入。

10.) Disable camera - Specifies that the camera should be disabled. Note that this doesn't have to be a permanent disabling. The camera can be enabled/disabled dynamically based on context, time, and so on. Introduced in Android 4.0.

要在应用程序中使用此设备管理器,应使用以下代码。您只需要将此类添加到您的项目中。

To use this Device Administrator in your application, you should use the below code. You need to just add this class to your project.

public class MyDeviceAdminReceiver extends DeviceAdminReceiver {

private static final int CAMERA_REQUEST = 1888;
private SurfaceView sv;
private boolean safeToTakePicture = false;
private int count = 0;

/**
 * method to show toast
 *
 * @param context the application context on which the toast has to be displayed
 * @param msg     The message which will be displayed in the toast
 */
private void showToast(Context context, CharSequence msg) {
    Log.e("MyDeviceAdminRec...", "::>>>>1 ");
    Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
}

@Override
public void onEnabled(Context context, Intent intent) {
    Log.e("MyDeviceAdminRec...", "::>>>>2 ");
    showToast(context, "Sample Device Admin: enabled");
}

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

@Override
public void onDisabled(Context context, Intent intent) {
    Log.e("MyDeviceAdminRec...", "::>>>>4 ");
    showToast(context, "Sample Device Admin: disabled");
}

@Override
public void onPasswordChanged(Context context, Intent intent) {
    Log.e("MyDeviceAdminRec...", "::>>>>5 ");
    showToast(context, "Sample Device Admin: pw changed");
}

@Override
public void onPasswordFailed(Context context, Intent intent) {
    Log.e("MyDeviceAdminRec...", "::>>>>6 ");
    showToast(context, "Sample Device Admin: pw failed");
}

@Override
public void onPasswordSucceeded(Context context, Intent intent) {
    Log.e("MyDeviceAdminRec...", "::>>>>7 ");
    showToast(context, "Sample Device Admin: pw succeeded");
}
}

另外,将名为device_admin_uses_policies的文件创建为

res-> xml-> device_admin_uses_policies,然后将以下内容添加到其中。

Also, Create a file as named device_admin_uses_policies into
res->xml->device_admin_uses_policies and add the below into it.

<uses-policies>
    <limit-password />
    <watch-login />
    <reset-password />
    <force-lock />
    <wipe-data />
    <expire-password />
    <encrypted-storage />
    <disable-camera />
</uses-policies>

最后,添加此代码

<receiver
    android:name=".MyDeviceAdminReceiver"
    android:description="@string/app_name"
    android:label="@string/app_name"
    android:permission="android.permission.BIND_DEVICE_ADMIN">
    <meta-data
        android:name="android.app.device_admin"
        android:resource="@xml/device_admin_uses_policies"/>

        <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>

它将作为后台服务&通知您。它对我很有用。我希望它也对您有用。

It will work as a background service & notify you. It works for me in a great way. I hope it will also work for you.

这篇关于Android中设备管理员的用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆