Device administration)

Source: Internet
Author: User
Tags myadmin
Device administration)

Alexzhuang posted a total of 0 comments seven months ago.

Android 2.2 introduces support for enterprise applications by offering the Android device administration API.

Since Android, Android has provided an API for device management. We can use this API to remotely delete data, Set lock screen passwords, and perform other system-level operations.

For details, see: http://developer.android.com/guide/topics/admin/device-admin.html

The following describes how to develop a device management application:

1. Create a broadcast receiver for MyAdmin to inherit deviceadminreceiver

Androidmanifest. xml

<receiver android:name=".MyAdmin"><meta-data android:name="android.app.device_admin"android:resource="@xml/my_admin" /><intent-filter><action android:name="android.app.action.DEVICE_ADMIN_ENABLED" /></intent-filter></receiver>

MyAdmin. Java

package com.alex.mobilesafe.receiver;import android.app.admin.DeviceAdminReceiver;public class MyAdmin extends DeviceAdminReceiver {}

2. Create an XML file: Res/XML/my_admin.xml

<?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 />        </uses-policies></device-admin>

3. register the broadcast receiver as the admin device.

DevicePolicyManager manager = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);ComponentName mAdminName = new ComponentName(this, MyAdmin.class);if (!manager .isAdminActive(mAdminName)) {Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,mAdminName);startActivity(intent);}

4. Use devicepolicymanager

Lock screen and set the Lock password

DevicePolicyManager manager =                     (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);manager.resetPassword("123", 0);manager.lockNow();

Remote Data Deletion

DevicePolicyManager manager =                     (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);manager.wipeData(0);

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.