Android Open Source - LockScreen Screen Receiver






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;
/*ww  w  .  java  2 s.c o m*/
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.widget.Toast;

public class ScreenReceiver extends BroadcastReceiver{
  
  private TelephonyManager tm = null;
  private boolean isPhoneIdle = true;

  @Override
  public void onReceive(Context context, Intent intent) {
    
    Toast.makeText(context, "BoradCastReceiver ??!", Toast.LENGTH_SHORT).show();
    
    if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
      
      if(tm == null) {
        tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        tm.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
      }
      
      if(isPhoneIdle) {
        Intent i = new Intent(context, MainActivity.class);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); //???? ???? / ???? ??? ? ?????? ??? ????? ???? ?? 
        context.startActivity(i);
      }
    }
  }
  
  private PhoneStateListener phoneListener = new PhoneStateListener() {
    public void onCallStateChanged(int state, String incomingNumber) {
      switch (state) {
      case TelephonyManager.CALL_STATE_IDLE : //???????
        isPhoneIdle = true;
        break;
        
      case TelephonyManager.CALL_STATE_RINGING : //??? ?
        isPhoneIdle = false;
        break;
        
      case TelephonyManager.CALL_STATE_OFFHOOK : //???
        isPhoneIdle = false;
        break;
      }
    };
  };
}




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