posted by 블르샤이닝 2020. 3. 24. 15:52
728x90

참조 사이트 : http://blog.naver.com/PostView.nhn?blogId=i_ehdfyd&logNo=50134133828

Android 에서 전화 걸때 수신 및 발신번호 잡아내기  case : Android   

2012. 2. 15. 18:39

http://blog.naver.com/i_ehdfyd/50134133828

번역하기

// PhoneStateReceiver.java

 

package kr.test.receiver;

 

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.telephony.PhoneStateListener;

import android.telephony.TelephonyManager;

import android.util.Log;

 

public class PhoneStateReceiver extends BroadcastReceiver

{

public void onReceive(Context context, final Intent intent)

{

   if(intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL))   

   {

      // 발신

      // intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

      }

       

       TelephonyManager telManager =(TelephonyManager) 

                context.getSystemService(Context.TELEPHONY_SERVICE);

       telManager.listen(new myPhoneStateListener(intent),

PhoneStateListener.LISTEN_CALL_STATE);

    }

}

 

/*

 * Intent.ACTION_NEW_OUTGOING_CALL 은 발신 할 때만 들어간다.

 * Intent.ACTION_NEW_OUTGOING_CALL 은

    '전화버튼을 누른다' -> 요기 쯤 -> '전화가 간다'

 * Intent.ACTION_NEW_OUTGOING_CALL 을 사용하려면

   android.permission.PROCESS_OUTGOING_CALLS

   android.intent.action.NEW_OUTGOING_CALL

   이렇게 두개가 필요하다.

  * 좀더 자세한 구분은 myPhoneStateListener 에서 한다.

 */

   

// myPhoneStateListener.java

 

package kr.test.receiver;

 

import android.telephony.PhoneStateListener;

import android.telephony.TelephonyManager;

import android.util.Log;

 

public class myPhoneStateListener extends PhoneStateListener

{

   private static int pState = TelephonyManager.CALL_STATE_IDLE;     

   private Intent intent;

      

   public myPhoneStateListener(Intent _intent)

 

   {

   super();

   intent = _intent;

   }

      

// 발신 : IDLE -> OFFHOOK -> IDLE

// 수신 : IDLE -> RINGING -> OFFHOOK -> IDLE

   public void onCallStateChanged(int state, String incomingNumber)

   {

      if(state != pState)

      {

         if(state == TelephonyManager.CALL_STATE_IDLE)

            Log.i("Phone","IDLE ;; number : " + incomingNumber );

         else if(state == TelephonyManager.CALL_STATE_RINGING)

            Log.i("Phone","RINGING ;; number : " + incomingNumber );

         else if(state == TelephonyManager.CALL_STATE_OFFHOOK)

            Log.i("Phone","OFFHOOK ;; number : "+

                 intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

           

         pState = state;

     }

   }

}

 

/*

 * 수신시에는 incomingNumber 이 수신번호를 가지고 있다

 * 발신 시에는 intent.getSeringExtra(Intent.EXTRA_PHONE_NUMBER) 에서 확인 할 수 있다.

 * 발신시 일반 모드에서 바로 OFFHOOK 로 가므로 그곳에서 확인 해보았다. 

 */

 

 

// Manifest.xml

 

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="kr.test.receiver"

    android:versionCode="1"

    android:versionName="1.0" >

 

   <uses-sdk android:minSdkVersion="8" />

   <uses-permission  

       android:name="android.permission.READ_PHONE_STATE"/>

   <uses-permission 

       android:name="android.permission.CALL_PRIVILEGED" />

<uses-permission

     android:name="android.permission.PROCESS_OUTGOING_CALLS"/>

 

   <application

        android:icon="@drawable/ic_launcher"

        android:label="@string/app_name" >

     <receiver android:name=".PhoneStateReceiver" >

<intent-filter>

          <action 

            android:name="android.intent.action.NEW_OUTGOING_CALL"/>

          <action android:name="android.intent.action.PHONE_STATE"/>

        </intent-filter>

</receiver>

   </application>

</manifest>

 

// ------------------------------------------------------------

 

/* 프로젝트에 BroadcastReceiver 만 존재한다면, 

Console 에

 

 

[2012-02-15 18:20:28 - CallReceiverTest] Installing CallReceiverTest.apk...

[2012-02-15 18:20:29 - CallReceiverTest] Success!

[2012-02-15 18:20:29 - CallReceiverTest] \CallReceiverTest\bin\CallReceiverTest.apk installed on device

[2012-02-15 18:20:29 - CallReceiverTest] Done!

 

이렇게 뜨는것이 정상이다.

 

Activity 가 없으므로 화면에 아무것도 나타나지 않으며, 전화를 걸어보거나 받아보면 Log에 번호가 나타나는것을 확인 할 수 있다.

*/

 

[출처] Android 에서 전화 걸때 수신 및 발신번호 잡아내기|작성자 빨간등대

728x90

'포렌식 > 스마트폰' 카테고리의 다른 글

Odin3_v3.13.1  (0) 2021.03.17
dm 확장자 파일  (0) 2021.03.12
apk 디버깅 하기 좋은 사례  (0) 2020.03.06
안드로이드 studio sdk 설치 방법  (0) 2020.01.16
FRP HiJacker By Hagard  (0) 2019.05.21