自定义锁屏demo之按键屏蔽等其他细节

1.屏蔽back键:

public boolean onKeyDown(int keyCode ,KeyEvent event){
 
  if(event.getKeyCode() == KeyEvent.KEYCODE_BACK)
  return true ;
  else
  return super.onKeyDown(keyCode, event);
 
  }

2.屏蔽home键(需要api5以上):


    @Override
  public void onAttachedToWindow() {
  this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
     super.onAttachedToWindow();
      }


6.防止接听电话时锁屏:

oncreate中调用:

 TelephonyManager mTelephonyMgr = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);  
        mTelephonyMgr.listen(new TeleListener(),PhoneStateListener.LISTEN_CALL_STATE);  
        


class TeleListener extends PhoneStateListener{  


    @Override  
    public void onCallStateChanged(int state, String incomingNumber) {  
    super.onCallStateChanged(state, incomingNumber);  


    switch (state) {
    //空闲
    case TelephonyManager.CALL_STATE_IDLE: { 
    break;
    }  


    //接通
    case TelephonyManager.CALL_STATE_OFFHOOK: { 
    finish();
    break;  
    }  
   
    //振铃
    case TelephonyManager.CALL_STATE_RINGING: {  
    finish();
    break;
    }  


    default:  


    break;  


    }  


    }  
    }

7.开机自启动:

<receiver android:name=".OpenMbBcReceiver">    
            <intent-filter>    
                <action android:name="android.intent.action.BOOT_COMPLETED"/>      
            </intent-filter>    
        </receiver> 

 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>



你可能感兴趣的:(demo)