2015-10-05 154 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

相关问题