Android Open Source - example-lock-app Lock Device Receiver






From Project

Back to project page example-lock-app.

License

The source code is released under:

Apache License

If you think the Android project example-lock-app listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.lockapp;
//  ww w  . j  a v  a  2  s . co m
import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class LockDeviceReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {
    DevicePolicyManager devicePolicyManager = (DevicePolicyManager)context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    ComponentName lockDeviceComponent = new ComponentName(context, MainActivity.LockAppDeviceAdmin.class);
    if (devicePolicyManager.isAdminActive(lockDeviceComponent))
    {
      try {
          devicePolicyManager.lockNow();
      } catch (SecurityException se) {
        Toast.makeText(context, "Could not lock", Toast.LENGTH_SHORT).show();
      }
    }
        else {
            Toast.makeText(context, "Admin privilege required", Toast.LENGTH_SHORT).show();
        }
  }
}




Java Source Code List

com.lockapp.AboutActivity.java
com.lockapp.LockDeviceReceiver.java
com.lockapp.LockWidgetProvider.java
com.lockapp.MainActivity.java
com.lockapp.fragments.FragmentUtils.java
com.lockapp.fragments.NotificationStatus.java
com.lockapp.fragments.PromptUtils.java
com.lockapp.fragments.lollipop.ControlsFragment.java
com.lockapp.fragments.lollipop.ControlsUtils.java
com.lockapp.fragments.lollipop.PromptFragment.java
com.lockapp.fragments.others.ControlsFragment.java
com.lockapp.fragments.others.PromptFragment.java