register Device Admin - Android Hardware

Android examples for Hardware:Device Feature

Description

register Device Admin

Demo Code


//package com.java2s;
import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;

import android.content.Intent;

public class Main {
    private static ComponentName mComponentName;

    public static void registerDeviceAdmin(final Activity activity,
            final int requestCode) {
        Intent intent = new Intent(
                DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
                getComponentName());//from  w w  w . j ava 2 s.c  om
        intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                "Needs to run as a Device Administrator to prevent uninstalling the app");
        activity.startActivityForResult(intent, requestCode);
    }

    public static ComponentName getComponentName() {
        return mComponentName;
    }
}

Related Tutorials