"Enable device admin" page not showing

403 views Asked by At

I got a strange problem i wanna show user the device admin page in setting for set my app as admin but i don't know why after create the intent nothing happened!

here is my all codes:

code for showing page:

ComponentName componentName = new ComponentName(context, DeviceAdminReceiver.class);
            Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
            intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);
            intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Example");
            startActivityForResult(intent,1);

in manifests:

<receiver
        android:name=".receivers.DevicePolicyReceiver"
        android:permission="android.permission.BIND_DEVICE_ADMIN">
        <meta-data android:name="android.app.device_admin"
            android:resource="@xml/device_admin" />
        <intent-filter>
            <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
            <action android:name="android.app.action.ACTION_DEVICE_ADMIN_DISABLE_REQUESTED" />
            <action android:name="android.app.action.ACTION_DEVICE_ADMIN_DISABLED" />
        </intent-filter>
    </receiver>

DevicePolicyReceiver.java

public class DevicePolicyReceiver extends DeviceAdminReceiver {

@Override
public void onDisabled(Context context, Intent intent) {

}

@Override
public void onEnabled(Context context, Intent intent) {

}

@Override
public CharSequence onDisableRequested(Context context, Intent intent) {
    CharSequence disableRequestedSeq = "Requesting to disable Device Admin";
    return disableRequestedSeq;
}

@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);
}

}

device_admin.xml

<?xml version="1.0" encoding="utf-8"?>

<uses-policies>
    <disable-camera />
</uses-policies>

i see other people ask this question but that didn't solve my problem. please help me i don't know why it shows nothing!

1

There are 1 answers

0
JeffNhan On

Try adding

super.onEnabled(context, intent);

inside onEnabled.