Unable to activate app as device admin on android oreo(API level 26)

395 Views Asked by At

When I try to activate my app as device admin an click Activate this device admin app, I am sent back to the previous screen and the device admin is not activated.

Receiver in manifes:

<receiver
        android:name=".MyDeviceAdminReceiver"
        android:permission="android.permissions.BIND_DEVICE_ADMIN">
        <meta-data
            android:name="android.app.device_admin"
            android:resource="@xml/device_admin_policies" />

        <intent-filter>
            <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
        </intent-filter>
</receiver>

Receiver class:

public class MyDeviceAdminReceiver extends DeviceAdminReceiver
{
    public void onEnabled(@NonNull Context context, @NonNull Intent intent)
    {
        Log.d("DeviceAdmin", "OnEnabled");
        super.onEnabled(context, intent);
        SharedPreferences.Editor defaultPrefEditor = PreferenceManager.getDefaultSharedPreferences(context).edit();
        defaultPrefEditor.putBoolean(context.getString(R.string.pref_device_admin_status), true);
        defaultPrefEditor.apply();
    }

    @Override
    public void onDisabled(@NonNull Context context, @NonNull Intent intent)
    {
        Log.d("DeviceAdmin", "OnDisabled");
        super.onDisabled(context, intent);
        SharedPreferences.Editor defaultPrefEditor =     PreferenceManager.getDefaultSharedPreferences(context).edit();
        defaultPrefEditor.putBoolean(context.getString(R.string.pref_device_admin_status), false);
        defaultPrefEditor.apply();

    }
}
1

There are 1 best solutions below

0
On BEST ANSWER

Found it!

android:permission="android.permissions.BIND_DEVICE_ADMIN"

I wrote permissions when it should be permission.