Error: Unknown admin: ComponentInfo{com.demoapp.amm/DeviceAdminSample}

1.2k Views Asked by At

I am trying this command from adb shell

dpm set-device-owner com.demoapp.amm/DeviceAdminSample

and i am getting this response.

Unknown admin: ComponentInfo{com.demoapp.amm/DeviceAdminSample}

com.demoapp.amm is my package name in Manifest file.

Below is my receiver from Manifest file

  <receiver
        android:name=".DeviceAdminSample"
        android:description="@string/sample_device_admin_description"
        android:label="@string/sample_device_admin_description"
        android:permission="android.permission.BIND_DEVICE_ADMIN" >

        <meta-data
            android:name="android.app.device_admin"
            android:resource="@xml/device_admin_sample" >
        </meta-data>

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

Below is My Class DeviceAdminSample.class

package com.demoapp.amm;
import android.app.admin.DeviceAdminReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;


public class DeviceAdminSample extends DeviceAdminReceiver {

void showToast(Context context, String msg) {

    Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
}

@Override
public void onEnabled(Context context, Intent intent) {
    showToast(context,"Enabled");
}

@Override
public CharSequence onDisableRequested(Context context, Intent intent) {
    return "Disabled";
}

@Override
public void onDisabled(Context context, Intent intent) {
    showToast(context, "Disabled");
}

@Override
public void onPasswordChanged(Context context, Intent intent) {
    showToast(context,"Password Change");
}

public static ComponentName getComponentName(Context context) {
    return new ComponentName(context.getApplicationContext(), 
DeviceAdminSample.class);
}

}
1

There are 1 best solutions below

0
On

It's because you've prefixed a period to the receiver name within your manifest android:name=".DeviceAdminSample" Thus com.demoapp.amm/DeviceAdminSample doesnt exist.

Try instead dpm set-device-owner com.demoapp.amm/.DeviceAdminSample.