Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何获取模式或密码写入错误的消息_Java_Android - Fatal编程技术网

Java 如何获取模式或密码写入错误的消息

Java 如何获取模式或密码写入错误的消息,java,android,Java,Android,我想要一个功能,计数,甚至得到的密码或模式的手机写错了 public int number_of_times () <intent-filter> <action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/> <action android:name="android.app.action.ACTION_PASSWORD_CHANGE

我想要一个功能,计数,甚至得到的密码或模式的手机写错了

public int number_of_times ()
        <intent-filter>
            <action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_CHANGED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_FAILED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_SUCCEEDED"/>
        </intent-filter>
    </receiver>
} 返回次数;
}

只有在使用设备管理API的情况下,才能执行此操作。具体而言,您需要:

        <intent-filter>
            <action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_CHANGED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_FAILED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_SUCCEEDED"/>
        </intent-filter>
    </receiver>
一个DeviceAdminReceiver子类,适当地注册在清单中,您可以在其中发现密码失败

        <intent-filter>
            <action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_CHANGED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_FAILED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_SUCCEEDED"/>
        </intent-filter>
    </receiver>
设备管理元数据,表示您希望获得有关设备管理失败的通知

        <intent-filter>
            <action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_CHANGED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_FAILED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_SUCCEEDED"/>
        </intent-filter>
    </receiver>
帮助用户进入设置应用程序并以设备管理员身份启用应用程序的UI

        <intent-filter>
            <action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_CHANGED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_FAILED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_SUCCEEDED"/>
        </intent-filter>
    </receiver>
作为一个稍大的示例的一部分,演示了所有这些,该示例还设置了密码质量要求

        <intent-filter>
            <action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_CHANGED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_FAILED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_SUCCEEDED"/>
        </intent-filter>
    </receiver>
需要注意的是,清单中my AdminReceiver的元素通过在my:

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

        <intent-filter>
            <action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_CHANGED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_FAILED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_SUCCEEDED"/>
        </intent-filter>
    </receiver>
此外,my AdminReceiver是DeviceAdminReceiver和overrides onPasswordFailed的子类,用于查找故障:

        <intent-filter>
            <action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_CHANGED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_FAILED"/>
            <action android:name="android.app.action.ACTION_PASSWORD_SUCCEEDED"/>
        </intent-filter>
    </receiver>
/***
  Copyright (c) 2013 CommonsWare, LLC
  Licensed under the Apache License, Version 2.0 (the "License"); you may not
  use this file except in compliance with the License. You may obtain a copy
  of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
  by applicable law or agreed to in writing, software distributed under the
  License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
  OF ANY KIND, either express or implied. See the License for the specific
  language governing permissions and limitations under the License.

  From _The Busy Coder's Guide to Android Development_
    https://commonsware.com/Android
 */

package com.commonsware.android.pwenforce;

import android.app.admin.DeviceAdminReceiver;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class AdminReceiver extends DeviceAdminReceiver {
  @Override
  public void onEnabled(Context ctxt, Intent intent) {
    ComponentName cn=new ComponentName(ctxt, AdminReceiver.class);
    DevicePolicyManager mgr=
        (DevicePolicyManager)ctxt.getSystemService(Context.DEVICE_POLICY_SERVICE);

    mgr.setPasswordQuality(cn,
                           DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC);

    onPasswordChanged(ctxt, intent);
  }

  @Override
  public void onPasswordChanged(Context ctxt, Intent intent) {
    DevicePolicyManager mgr=
        (DevicePolicyManager)ctxt.getSystemService(Context.DEVICE_POLICY_SERVICE);
    int msgId;

    if (mgr.isActivePasswordSufficient()) {
      msgId=R.string.compliant;
    }
    else {
      msgId=R.string.not_compliant;
    }

    Toast.makeText(ctxt, msgId, Toast.LENGTH_LONG).show();
  }

  @Override
  public void onPasswordFailed(Context ctxt, Intent intent) {
    Toast.makeText(ctxt, R.string.password_failed, Toast.LENGTH_LONG)
         .show();
  }

  @Override
  public void onPasswordSucceeded(Context ctxt, Intent intent) {
    Toast.makeText(ctxt, R.string.password_success, Toast.LENGTH_LONG)
         .show();
  }
}