```kotlin
import android.app.admin.DevicePolicyManager
import android.content.ComponentName
import android.content.Context
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val devicePolicyManager = getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val componentName = ComponentName(this, DeviceAdminReceiver::class.java)
if (devicePolicyManager.isAdminActive(componentName)) {
devicePolicyManager.lockNow()
}
}
}
```
Pastikan juga kamu menambahkan receiver di dalam `AndroidManifest.xml`:
```xml
android:name=".DeviceAdminReceiver"
android:permission="android.permission.BIND_DEVICE_ADMIN">
android:name="android.app.device_admin"
android:resource="@xml/device_admin_receiver"/>
```
File `device_admin_receiver.xml`:
```xml