设备通话时禁用自己的锁屏

时间:2013-01-22 08:03:54

标签: java android telephonymanager phone-call phone-state-listener

我使用Intent.ACTION_SCREEN_OFFIntent.ACTION_SCREEN_ON创建自己的LockScreen。但是当我打电话时它仍然有效。我引用了这段代码,但它没有用。

         StateListener phoneStateListener = new StateListener();
        TelephonyManager telephonymanager =  (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
        telephonymanager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
    }catch(Exception e){ }

}
   class StateListener extends PhoneStateListener{
        @Override
   public void onCallStateChanged(int state, String incomingNumber)     {

              super.onCallStateChanged(state, incomingNumber);
              switch(state){
              case TelephonyManager.CALL_STATE_RINGING:
                    break;
              case TelephonyManager.CALL_STATE_OFFHOOK:
                    System.out.println("call Activity off hook");

        // Finish lock screen activity
                    finish();
                    break;
              case TelephonyManager.CALL_STATE_IDLE:
                    break;
              }
        }
  };

0 个答案:

没有答案