我正在开发一个安全应用程序,可以保护设备免受陌生人的侵害.
在我的应用程序中,如果用户尝试使用错误的PIN /图案/密码解锁设备,我应该具有从前置摄像头捕获图像的功能.
我有这样的代码.
public class MyadminReceiver extends DeviceadminReceiver { @OverrIDe public voID onPasswordFailed(Context context, Intent intent, UserHandle user) { Log.d("mytag", "onPasswordFailed called"); //Code for starting a service for image capture goes here . . . } .... ....}
在几乎所有版本中,我都可以正确捕获图像,并且该应用程序运行正常.
问题是:在某些设备中,功能onPasswordFailed不起作用.设备管理员已正确激活.我尝试再次禁用它并重新激活它.我尝试重新启动设备.但是没有任何效果.我可以在我的堆栈跟踪中看到此日志.
03-09 12:04:48.078 18491-18491/com.my.pkgname D/ActivityThread: BDC-Calling onReceive: intent=Intent { act=androID.app.action.ACTION_PASSWORD_Failed flg=0x10 cmp=com.my.pkgname/.receivers.MyadminReceiver }, receiver=com.my.pkgname.receivers.MyadminReceiver@30c2044b03-09 12:04:48.079 18491-18491/com.my.pkgname D/ActivityThread: BDC-RECEIVER handled : 0 / ReceiverData{intent=Intent { act=androID.app.action.ACTION_PASSWORD_Failed flg=0x10 cmp=com.my.pkgname/.receivers.MyadminReceiver } packagename=com.my.pkgname resultCode=-1 resultData=null resultExtras=null}
到目前为止,在所有我能看到的AndroID 6.0(棉花糖版本)和AndroID 7.1.1(如果有帮助的话,它的Motorola设备)中都可以看到此问题.
我已经检查了以下问题:
> Android 4.0 Device Admin Receiver not working
> Android Device Admin not working
> Having trouble receiving ACTION_PASSWORD_SUCCEEDED and ACTION_PASSWORD_FAILED intents
它们与我的admin.xml文件无关,并且清单声明很好,并且可以在所有其他版本为AndroID 7、8、9的设备中使用.
我已经测试过使用模式,有效的PIN超过了最小长度.我根本没有设置其他密码限制.
我仍然向清单部分显示admin.xml进行验证.
清单声明:
....<application> .... <receiver androID:name=".receivers.MyadminReceiver" androID:exported="true" androID:enabled="true" androID:permission="androID.permission.BIND_DEVICE_admin"> <Meta-data androID:name="androID.app.device_admin" androID:resource="@xml/admin" /> <intent-filter> <action androID:name="androID.app.action.DEVICE_admin_ENABLED" /> <action androID:name="androID.app.action.DEVICE_admin_disABLE_REQUESTED" /> </intent-filter> </receiver> ....</application>
admin.xml文件:
<device-admin xmlns:androID="http://schemas.androID.com/apk/res/androID"> <uses-policIEs> <watch-login /> </uses-policIEs></device-admin>
有人可以解决这个问题吗?
让我知道是否需要任何特殊权限/或强制设置.
附注:我测试了一些代码更改.当我在admin.xml中添加必要的策略时,同一设备管理员可以正确执行lockNow()函数.因此,设备管理员已正确设置.那么,可能不会调用onPasswordFailed的问题是什么?
我还尝试在清单中为ACTION_PASSWORD_Failed添加意图过滤器.没什么区别.
<intent-filter> <action androID:name="androID.app.action.DEVICE_admin_ENABLED" /> <action androID:name="androID.app.action.ACTION_PASSWORD_Failed" /> <action androID:name="androID.app.action.ACTION_PASSWORD_SUCCEEDED"/></intent-filter>
解决方法:
voID onPasswordFailed(Context context,Intent intent,UserHandle user)仅适用于Oreo及更高版本.
为了向后兼容,还需要重写onPasswordFailed(Context context,Intent intent).这将使您的代码在Nougat及以下版本上运行.
总结以上是内存溢出为你收集整理的android-设备管理接收器在少数版本中不起作用全部内容,希望文章能够帮你解决android-设备管理接收器在少数版本中不起作用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)