Android Open Source - LockScreen Screen Service






From Project

Back to project page LockScreen.

License

The source code is released under:

Apache License

If you think the Android project LockScreen listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.github.pongdang.lockscreentest;
/*from  www  . j a va2s .c  om*/
import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;

public class ScreenService extends Service{

  private ScreenReceiver receiver = null;
  
  @Override
  public IBinder onBind(Intent intent) {
    return null;
  }
  
  @Override
  public void onCreate() {
    super.onCreate();
    
    receiver = new ScreenReceiver();
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
    registerReceiver(receiver, filter);
  }
  
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);
    
    if(intent !=null & intent.getAction() == null & receiver == null) {
      receiver = new ScreenReceiver();
      IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
      registerReceiver(receiver, filter);
    }
    
    //Notification notification = new Notification(R.drawable.ic_launcher, "??? ?????", System.currentTimeMillis());
    //notification.setLatestEventInfo(getApplicationContext(), "Screen Service", "Foreground? ?????", null);
    startForeground(1, new Notification());
    
    return START_REDELIVER_INTENT;
  }
  
  @Override
  public void onDestroy() {
    super.onDestroy();
    
    if(receiver != null)
      unregisterReceiver(receiver);
  }
}




Java Source Code List

com.github.pongdang.lockscreentest.DBHelper.java
com.github.pongdang.lockscreentest.MainActivity.java
com.github.pongdang.lockscreentest.ScreenReceiver.java
com.github.pongdang.lockscreentest.ScreenService.java