裝置管理應用程式的實現(Device Administration )

來源:互聯網
上載者:User
裝置管理應用程式的實現(Device Administration )

AlexZhuang 發佈於 7個月前,共有 0 條評論

Android 2.2 introduces support for enterprise applications by offering the Android Device Administration API. 

從Android2.2 起,Android官方就提供了裝置管理API,我們可以通過這個API實現遠程刪除資料、設定鎖屏密碼等系統層級的操作。

具體詳見:http://developer.android.com/guide/topics/admin/device-admin.html

下面就是裝置管理應用程式開發的簡化實現步驟:

1.建立 MyAdmin 的廣播接受者 繼承 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. 建立XML檔案: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.註冊廣播接受者為admin裝置

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.使用DevicePolicyManager 

鎖屏並設定鎖頻密碼

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

遠程刪除資料

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.