public void changeLockCode(String code,String data){
  ComponentName demoDeviceAdmin=new ComponentName(context,AgentDeviceAdminReceiver.class);
  devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin,DEFAULT_PASSWORD_MIN_LENGTH);
  String password=null;
  try {
    JSONObject lockData=new JSONObject(data);
    if (!lockData.isNull(resources.getString(R.string.intent_extra_password))) {
      password=(String)lockData.get(resources.getString(R.string.intent_extra_password));
    }
    resultBuilder.build(code);
    if (password != null && !password.isEmpty()) {
      devicePolicyManager.resetPassword(password,DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
      devicePolicyManager.lockNow();
    }
  }
 catch (  JSONException e) {
    Log.e(TAG,"Invalid JSON format." + e);
  }
}

public void changeLockCode ( String code , String data ) { ComponentName demoDeviceAdmin = new ComponentName ( context , AgentDeviceAdminReceiver . class ) ; devicePolicyManager . setPasswordMinimumLength ( demoDeviceAdmin , DEFAULT_PASSWORD_MIN_LENGTH ) ; String password = null ; try { JSONObject lockData = new JSONObject ( data ) ; if ( ! lockData . isNull ( resources . getString ( R . string . intent_extra_password ) ) ) { password = ( String ) lockData . get ( resources . getString ( R . string . intent_extra_password ) ) ; } resultBuilder . build ( code ) ; if ( password != null && ! password . isEmpty ( ) ) { devicePolicyManager . resetPassword ( password , DevicePolicyManager . RESET_PASSWORD_REQUIRE_ENTRY ) ; devicePolicyManager . lockNow ( ) ; } } catch ( JSONException e ) { Log . e ( TAG , "Invalid JSON format." + e ) ; } }
change device lock code .
