2015-10-05 152 views
1

我使用此代碼來獲取模式鎖定,但它不起作用。我想鎖定按鈕點擊屏幕。鎖定屏幕以編程方式

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(); 
    } 
} 

我想要做這樣的enter image description here

+3

您的應用是設備管理員嗎? – Codebender

回答

-2

你試過this鏈接..

鎖定/解鎖屏幕

如果它不起作用,請嘗試使用ICS以外的其他安卓版本(如果使用的是ICS)

+0

我試過但沒有任何反應。沒有錯誤顯示沒有模式顯示 – Lakshan

+0

有沒有什麼在你的日誌? – droidev

相關問題