我正在尝试使用DevicePolicyManager将手机锁定在闹钟接收器中。我只是不能正确的语法,可能做一些愚蠢的事情...有人可以告诉我我的方式错误吗?
由于
public class AlarmReceiver extends BroadcastReceiver {
String Password = "LOCK";
String UnlockPassword = "UNLOCK";
ComponentName mDeviceAdmin;
private DevicePolicyManager mDPM;
@Override
public void onReceive(Context context, Intent intent) {
gcmaction();
Intent lockintent = new Intent(context, CurfewSetActivity.class);
lockintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
private void gcmaction() {
Log.i(TAG,"gcm lock action method started");
它的下两行是错误的(方法getSystemService(String)未定义类型AlarmReceiver)
mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
mDeviceAdmin = new ComponentName(this, AdminReceiver.class);
boolean active = mDPM.isAdminActive(mDeviceAdmin);
if (active) {
mDPM.resetPassword(Password,DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
mDPM.lockNow();
}
else Log.i(TAG,"Not an admin");
}
}
答案 0 :(得分:0)
替换
mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
与
mDPM = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
getSystemService
是Context
类的方法,因此您需要该类的对象才能访问它。