2014-11-24 31 views
5

好像有些DeviceAdmin功能已在棒棒糖被打破,至少在我的Nexus 5DevicePolicyManger()。getCurrentFailedPasswordAttempts崩潰的應用程序

這工作完全在奇巧,豆形軟糖和Ice Cream Sandwich的

@Override 
public void onPasswordFailed(Context context, Intent intent) { 

    DevicePolicyManager policyManager = (DevicePolicyManager)context.getSystemService(Context.DEVICE_POLICY_SERVICE); 
    if(policyManager != null){ 
     int attempts = policyManager.getCurrentFailedPasswordAttempts(); 
     Log.v("TAG", "Attempts = " + attempts); 
    } 
} 

但在我的Nexus 5採用Android 5.0棒棒糖它產生以下錯誤:

11-24 16:11:50.117 27053-27053/com.example.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main 
    Process: com.example.myapp, PID: 27053 
    java.lang.RuntimeException: Unable to start receiver com.example.myapp.receivers.AdminReceiver: java.lang.NullPointerException: Attempt to read from field 'int android.content.pm.UserInfo.id' on a null object reference 
      at android.app.ActivityThread.handleReceiver(ActivityThread.java:2586) 
      at android.app.ActivityThread.access$1700(ActivityThread.java:144) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:135) 
      at android.app.ActivityThread.main(ActivityThread.java:5221) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:372) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 
    Caused by: java.lang.NullPointerException: Attempt to read from field 'int android.content.pm.UserInfo.id' on a null object reference 
      at android.os.Parcel.readException(Parcel.java:1546) 
      at android.os.Parcel.readException(Parcel.java:1493) 
      at android.app.admin.IDevicePolicyManager$Stub$Proxy.getCurrentFailedPasswordAttempts(IDevicePolicyManager.java:2476) 
      at android.app.admin.DevicePolicyManager.getCurrentFailedPasswordAttempts(DevicePolicyManager.java:1261) 
      at com.example.myapp.receivers.AdminReceiver.onPasswordFailed(AdminReceiver.java:48) 
      at android.app.admin.DeviceAdminReceiver.onReceive(DeviceAdminReceiver.java:417) 
      at android.app.ActivityThread.handleReceiver(ActivityThread.java:2579) 
            at android.app.ActivityThread.access$1700(ActivityThread.java:144) 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355) 
            at android.os.Handler.dispatchMessage(Handler.java:102) 
            at android.os.Looper.loop(Looper.java:135) 
            at android.app.ActivityThread.main(ActivityThread.java:5221) 
            at java.lang.reflect.Method.invoke(Native Method) 
            at java.lang.reflect.Method.invoke(Method.java:372) 
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 

It's been reported as an issue in the L-preview as well.

我的問題,這是什麼原因造成的?

+0

僅供參考:我的應用程序有同樣的問題,所以你並不孤單。我用一個簡單的try catch塊「解決」它 - 至少應用程序不會再崩潰了。 – 2014-11-24 20:33:52

+0

感謝@TheisBorg - 現在,我只是保留一個靜態參考來解鎖嘗試,直到英雄來到並保存一天。 – Jakob 2014-11-25 07:37:05

回答

0

我有同樣的錯誤,然後我意識到,這可能不是爲5.0及更高版本versions.So工作,我所做的是我檢查錯誤的嘗試次數programmatically.Like如果有人想解鎖圖案或PIN如果他輸入錯誤,那麼接收方將捕獲並調用passwordFailed()方法。因此,我在SharedPreference對象上創建了一個對象,並存儲了調用passwordFailed()方法的數目。基於這一點,我得到了一些錯誤的模式。我認爲這是正確的方式或不我不知道。