我使用此代碼來獲取模式鎖定,但它不起作用。我想鎖定按鈕點擊屏幕。鎖定屏幕以編程方式
main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Lock"
android:onClick="lock"/>
</RelativeLayout>
MainActivity.java
public class MainActivity extends ActionBarActivity {
DevicePolicyManager mDPM;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
}
public void lock(View view) {
mDPM.lockNow();
}
}
您的應用是設備管理員嗎? – Codebender