Android Devices Administration Device Manager--implementation of one-button lock screen

Source: Internet
Author: User

Android Devices Administration Device Manager--Implementation of lock screen

Recently studied the safety of this piece of content, of course, I am the comparison of water, so there is no good knowledge points, but there are some unpopular things I can still talk about, take this lock screen to say, we are now on the market there are some key lock screen software

We can see that there are countless, so, in fact, when he started to use, all need to request Device Manager

We can see that we can use it only when we activate it, so what is he? In fact, when we activate, we can see all of his information in our phone's settings-security-Device Manager

We take this question and open our Android API guide to see

    • Address: http://www.android-doc.com/guide/topics/admin/device-admin.html
I. Equipment Management

Android 2.2 introduces an enterprise application that provides support for Android device Management API. The Device Management API provides device system-level management capabilities. These APIs allow you to create security-sensitive applications for enterprise settings, such as built-in Android e-mail applications that leverage new APIs to improve exchange support. In an e-mail application, an administrator can exchange execution password policies-including alphanumeric passwords or digital needles-that can be remotely erased by the device administrator (that is, restore the factory defaults to lost or stolen phones. Users can exchange their email and calendar data in sync.

Two. Device Management API Overview

The following example types of applications can use the Device Management API:

    • e-mail client.
    • Secure applications that remotely erase data
    • Device Management services and applications.
Three. How it works

You use the Device Management API to write device management applications that users install on their devices. The policies required for device management applications to execute.

    • The system administrator writes a device management application to perform a remote/local device security policy. These policies may be hard-coded applications or applications that can dynamically obtain policy servers from third parties.

    • The application is installed on the user's device. But Android does not currently have an automated configuration solution. Some of the ways system administrators may distribute application users are as follows:

      • Google Play
      • Other stores
      • Other means, such as email or website
    • The system prompts the user to enable the Device management application when this happens depending on how the application is implemented.

    • Once the user has enabled the device management application, they are their policy. Compliance with these policies often brings benefits, such as access to sensitive systems and data.

If the user does not enable the Device management application, it is still on the device, but in an inactive state. Users will not be affected by their policies, they will be opposite to the positive mentality without getting an example of any application, they may not be able to synchronize data.

If a user fails to comply with the policy (for example, if a user sets a password that violates the guidelines), it is up to the application to decide how to handle the problem. However, this usually causes the user to be unable to synchronize the data.

If a device tries to connect to a server that requires policy in the Device Management API, the support connection is not allowed. The Device Management API does not currently allow partial provisioning. In other words, if a device (for example, a legacy device) does not support all of the established policies, it allows the device to connect without a means.

If a device contains multiple administrators enabling applications, strict policy enforcement is performed. There is no way to target a specific management application.

To uninstall an existing device management application, the user needs to unregister the program as an administrator first.

The translation is a bit lame, but probably means that after you activate he is a policy, but you do not activate, is also possible, just out of the static state, you need to uninstall the application before you have to log off the device management permissions

So what should we do? He has a lot of policies, so let's take a rough look at

Four. One Button lock screen

OK, we're talking about so many concepts, it's better to just use code to illustrate

    • Next we will follow the document to implement

In fact, the official document is very detailed, first we have to define a receiver let him inherit deviceadminreceiver, we do not realize it for the time being

package com.lgl.lockone;import android.app.admin.DeviceAdminReceiver;/** * 锁屏 * Created by LGL on 2016/7/24. */publicclass LockReceiver extends DeviceAdminReceiver{}

Then we need to define the manifest file

 <receiver android:name=". Lockreceiver "android:label=" @string/sample_device_admin "android:description= "@string/sample_device_admin_description" android:permission="Android.permission.BIND_DEVICE_ADMIN">                                                <meta-data android:name="Android.app.device_admin"android: Resource="@xml/device_admin_sample" />                            <intent-filter>                <action android:name="Android.app.action.DEVICE_ADMIN_ENABLED" />            </intent-filter>        </receiver>

Here is necessary to say, first of all, the label, said the title, this should be known, and then the description description, when you activate the device will go to request, you can see, finally to bind a permission file, we are in res new an XML folder, Create a new Device_admin_sample

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

OK, after we're done, we'll go to the simplest implementation of the lock screen, need to use the Devicepolicymanager

 PackageCom.lgl.lockone;ImportAndroid.app.admin.DevicePolicyManager;ImportAndroid.content.Context;ImportAndroid.os.Bundle;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.view.View;ImportAndroid.widget.Button; Public  class mainactivity extends appcompatactivity {    PrivateButton Btnlock;PrivateDevicepolicymanager MDPM;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main);//Device Policy managerMDPM = (Devicepolicymanager) getsystemservice (Context.device_policy_service);        Btnlock = (Button) Findviewbyid (R.id.btnlock); Btnlock.setonclicklistener (NewView.onclicklistener () {@Override             Public void OnClick(View v) {//Lock screenMdpm.locknow ();    }        }); }}

Actually here is a button, and then go to Locknow request lock screen, but you will find that he error, prompt is no permission, this permission can not be the user's permission, we go to the device manager inside to see

Here, there is our application, above is we define in the list of the title and description, we tick, and then to implement the lock screen, you will find that you can, this is required we manually to open, but the majority of users will not know this matter, so we start the program we should go to activate, It's actually written on the document, so let's see.

ComponentName mDeviceAdminSample = new ComponentName(this, LockReceiver.class);        Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminSample);        intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,                "我是不是很帅");        startActivity(intent);

And then we'll look at the effect.

And we can change the lock screen password.

//重置密码 mDPM.resetPassword("12345678"0);

If you send an empty string that means no password, we can run it again.

OK, let's take a look at the logic of the homepage.

 PackageCom.lgl.lockone;ImportAndroid.app.admin.DevicePolicyManager;ImportAndroid.content.ComponentName;ImportAndroid.content.Context;ImportAndroid.content.Intent;ImportAndroid.os.Bundle;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.view.View;ImportAndroid.widget.Button; Public  class mainactivity extends appcompatactivity {    PrivateButton Btnlock;PrivateDevicepolicymanager MDPM;PrivateComponentName mdeviceadminsample;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_main); Mdeviceadminsample =NewComponentName ( This, Lockreceiver.class);//Device Policy managerMDPM = (Devicepolicymanager) getsystemservice (Context.device_policy_service);        Btnlock = (Button) Findviewbyid (R.id.btnlock); Btnlock.setonclicklistener (NewView.onclicklistener () {@Override             Public void OnClick(View v) {if(Mdpm.isadminactive (Mdeviceadminsample)) {//Lock screenMdpm.locknow ();//Reset PasswordMdpm.resetpassword ("123456",0); }Else{Intent Intent =NewIntent (devicepolicymanager.action_add_device_admin);                    Intent.putextra (Devicepolicymanager.extra_device_admin, mdeviceadminsample); Intent.putextra (Devicepolicymanager.extra_add_explanation,"I'm not very handsome.");                StartActivity (Intent);    }            }        }); }}

Basically no code, if you are interested to add group

Magical Journey to Android: 555974449Demo Download: Uploading

Android Devices Administration Device Manager--implementation of one-button lock screen

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.