package com.example.lock;
import android.app.Activity;
import android.app.KeyguardManager;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.widget.Toast;
public class Lock_Service extends Service {
private KeyguardManager km = null;
private KeyguardManager.KeyguardLock keylock = null;
private BroadcastReceiver br = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(intent.ACTION_SCREEN_ON)) {
Intent i = new Intent(context, Lock_Main.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
};
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
km = (KeyguardManager) this.getSystemService(Activity.KEYGUARD_SERVICE);
if (km != null) {
keylock.disableKeyguard();
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
IntentFilter filter = new IntentFilter("com.example.action.isAlive");
filter.addAction(Intent.ACTION_SCREEN_OFF);
registerReceiver(br, filter);
return Service.START_NOT_STICKY;
}
public void onDestroy() {
if (keylock != null) {
keylock.reenableKeyguard();
}
if (br != null)
unregisterReceiver(br);
}
}
화면 잠금기능을 구현하고 있는데.
어디가 문제인가요 ㅠ 화면 잠금이 나오지 않습니다.
메인 부분에서는 setContentView(R.layout.activity_main); 화면을 불러오며,
startService(new Intent(this, Lock_Service.class));
서비스하여 불러옵니다.
KeyguardLock이 이렇게 노랗게 표시됩니다.