我试图锁定设备并尝试使用以下代码启用它,但它不起作用。我还获得了以下两个许可并且没有显示该手机已锁定......我也尝试再次解锁它。
public class LockPhoneActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
Button lock, unlock;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lock = (Button) findViewById(R.id.button1);
unlock = (Button) findViewById(R.id.button2);
lock.setOnClickListener(this);
unlock.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.button1:
KeyguardManager mgr = (KeyguardManager) getSystemService(Activity.KEYGUARD_SERVICE);
KeyguardLock lock = mgr.newKeyguardLock(KEYGUARD_SERVICE);
lock.reenableKeyguard();
Toast.makeText(getApplicationContext(), "Locked", Toast.LENGTH_LONG)
.show();
break;
case R.id.button2:
KeyguardManager mgr1 = (KeyguardManager) getSystemService(Activity.KEYGUARD_SERVICE);
KeyguardLock lock1 = mgr1.newKeyguardLock(KEYGUARD_SERVICE);
lock1.disableKeyguard();
break;
}
}
}
我还获得了以下许可...
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>