1
所以我有被註冊爲BroadcastReceiver
:DevicePolicyManager`lockNow();'不工作裝置重啓後
<receiver
android:name="package.MyBroadcastReceiver"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="999">
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
,我使用DevicePolicyManager
儘快用戶鎖定設備解鎖設備 - 如MyBroadcastReceiver
下面接收廣播見代碼:
@Override
public void onReceive(final Context context, final Intent intent) {
deviceManger = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
Runnable runnable = new Runnable() {
@Override
public void run() {
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(startMain);
deviceManger = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
//also tried with context..getApplicationContext() but no luck
deviceManger.lockNow();
}
}
};
}
所以這個代碼工作正常,但在設備關機並重新啓動,則:
deviceManger = (DevicePolicyManager) context.getApplicationContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
deviceManger.lockNow();
上面的內容似乎對設備沒有任何影響,即設備不會鎖定,但在設備重新啓動之前該設備工作正常。 我嘗試添加記錄,我相信代碼得到執行,但locknow()
似乎對設備沒有影響......
任何幫助表示讚賞