我正在从adb shell尝试此命令
dpm set-device-owner com.demoapp.amm / DeviceAdminSample
我得到了这个答复。
未知管理员:ComponentInfo {com.demoapp.amm / DeviceAdminSample}
com.demoapp.amm是清单文件中的包名称。
以下是我来自清单文件的收件人
<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>
下面是我的类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);
}
}
答案 0 :(得分:0)
这是因为您在清单android:name =“。DeviceAdminSample”中为接收者名称添加了句点前缀,因此com.demoapp.amm / DeviceAdminSample不存在。
请改用dpm set-device-owner com.demoapp.amm / .DeviceAdminSample。