-4
public void onReceive(Context context, Intent intent) {
context.startService(new Intent(context,MyPhoneStateListener.class));
MyPhoneStateListener lst=new MyPhoneStateListener(context);
TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(lst, PhoneStateListener.LISTEN_CALL_STATE);
}
public IBinder onBind(Intent arg0)
{ // TODO Auto-generated method stub return null;
}
}
// class MyPhoneStateListener extends PhoneStateListener
{
//private static final String TAG = "PhoneStateChanged";
Context context;
//Context to make Toast if required
public MyPhoneStateListener(Context context)
{
super();
this.context = context;
}
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
switch (state)
{
case TelephonyManager.CALL_STATE_IDLE: //when Idle i.e no call
Toast.makeText(context, "Phone state Idle", Toast.LENGTH_LONG).show();
break;
case TelephonyManager.CALL_STATE_OFFHOOK: //when Off hook i.e in call //Make intent and start your service here Toast.makeText(context, "Phone state Off hook", Toast.LENGTH_LONG).show();
break;
case TelephonyManager.CALL_STATE_RINGING: //when Ringing Toast.makeText(context, "Phone state Ringing", Toast.LENGTH_LONG).show();
break;
default: break;
} } }
사용자가 전화를 걸 때 응용 프로그램을 종료하려면 응용 프로그램을 개발해야합니다. 먼저 해당 번호가 저장되어 있는지 여부를 데이터베이스에서 감지해야합니다. 어느 쪽이 더 좋은 생각인가. 서비스 또는 브로드 캐스트 리시버를 사용하려면 통화를 끝내려면 지난 1 주 동안 시도한 코드를 사용하십시오. 나는 브로드 캐스트 리시버를 사용했으나, 리시버를 제외하고는 다른 액티비티 strts를 호출 할 때 도움이되지 않았다.누군가가 호출 할 때 전화를 끊을 때
<receiver
android:exported="true"
android:name=".receiver.OutgoingCall" >
<intent-filter android:priority="0" >
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
그런 다음 다음과 같습니다 당신은 당신의 매니페스트에 수신기를 등록해야
:
누구가 내 친애하는 친구에게 질문하고 편집 할 예정입니까? –
전화 건 번호가 목록에 없을 때 발신 전화를 끊으시겠습니까? – kingston