Вопрос

I'm trying to implement locking the screen with my app. I've worked my way through google documentation and studied the sample.

When i call this

    void getAdmin(){
    Intent activateDeviceAdminIntent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        activateDeviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mPolicy.getPolicyAdmin());
        activateDeviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                getResources().getString(R.string.AdminReceiverDescr));
        startActivityForResult(activateDeviceAdminIntent, REQ_ACTIVATE_DEVICE_ADMIN);
}

The dialogue doesn't show up (maybe it flashes a little, can't say for sure), it just jumps in my onResult routine and result is "not granted". But my app afterwards shows up in the list in settings/security/device admins and if i enable admin rights manually it locks my screen like a charm.

I've added the permission

uses-permission android:name="android.permission.BIND_DEVICE_ADMIN"

as well as

receiver ... android:permission="android.permission.BIND_DEVICE_ADMIN"

to my manifest.

Does anyone have a clue what i may have missed? Thx in advance!

Это было полезно?

Решение

Found the problem in my manifest: you have to specify the receiver subclass with a $ sign.

Example: android:name="com.exampl.PolicyClass$PolicyReceiver"

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top