달력

5

« 2024/5 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
728x90
반응형

안드로이드 - 전화 수신 상태 감지

원본출처:http://hekamedia.egloos.com/3578345 

package org.kandroid.sample;

import android.app.Activity;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;

import android.util.Log;

public class SamplePhoneState extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MyPhoneStateListener phoneListener=new MyPhoneStateListener();
TelephonyManager telephonyManager =(TelephonyManager)getSystemService(TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);

}

public class MyPhoneStateListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state,String incomingNumber){
if (state == TelephonyManager.CALL_STATE_IDLE) {
Log.i("PhoneCallState", "STATE_IDLE : Incoming number "+incomingNumber);
}
else if (state == TelephonyManager.CALL_STATE_RINGING) {
Log.i("PhoneCallState", "STATE_RINGING : Incoming number "+incomingNumber);
}
else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
Log.i("PhoneCallState", "STATE_OFFHOOK : Incoming number "+incomingNumber);
}
}
}

}
728x90
반응형
:
Posted by mapagilove