2012-03-28 3 views
1

가능한 중복 :
launching my app when dialing a number내 응용 프로그램에서 전화 건 번호를 얻으려면 어떻게해야합니까?

나는 다음과 같은 응용 프로그램을 구현 한 내 안드로이드 application.I에서 사용자가 다이얼 한 전화 걸기에서 휴대 전화 번호를 좀하고 싶습니다 :

((Button)findViewById(R.id.button1)).setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"))); 

     } 
    }); 

위의 코드에서 전화 걸기 앱을 열 수 있습니다. 사용자가 휴대 전화 번호를 입력하고 통화하려면 클릭하십시오. 그가 입력 한 번호. 하시기 바랍니다 내가 당신이 할 것을 BroadcastReceiverto를 사용할 수있는 코드를

public class OutGoingCall extends BroadcastReceiver { 

    @Override 
    public void onReceive(final Context context, final Intent intent) 
    { 
     // get phone number from bundle 
     String phoneNumber = intent.getExtras().getString(OutGoingCall.INTENT_PHONE_NUMBER); 

    } 
} 
+3

나는이 스레드의 폐쇄에 동의를 - 모든 페치에서 논의되지 않는다 "중복" 전화 번호. 또한 거기에 대한 대답은 훨씬 낮은 가치입니다. 스레드를 닫으려면 다른 스레드를 닫으십시오. –

+0

나는 또한 이와 같은 것을 시도하고있다. 하지만 전화가 다이얼러 앱에서 전화가 걸리 자마자 전화를 받기 전에 전화 번호를 받고 싶습니다. 어떤 몸도 도와 줄 수 있습니까? –

답변

0

:

는 매니페스트 파일에이 같은 브로드 캐스트 리시버를 등록

<!-- DIAL Receiver --> 
    <receiver 
     android:exported="true" 
     android:name="receivers.DialBroadcastReceiver" > 
     <intent-filter > 
      <action android:name="android.intent.action.NEW_OUTGOING_CALL" /> 
     </intent-filter> 
    </receiver> 

NEW_OUTGOING_CALL에 대한 액세스 권한이 필요합니다.

,210
<!-- OUTGOING CALL PERMISSION--> 
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" /> 

결국 당신은 방송을 수신하고이 같은 전화를 건 번호 검색 할 수 있습니다

public class DialBroadcastReceiver extends BroadcastReceiver { 

@Override 
public void onReceive(Context context, Intent intent) { 

    Log.v("DileBroadCastReceiver","In onReceive()"); 

    if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) { 
     String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); 

     Log.v("DialBroadcast Receiver","Number is: "+number); 

    } 

} 

}

+0

의도 i = 새로운 의도 (Intent.ACTION_DIAL, Uri.parse ("tel :"+ phoneno)); –

+0

다음과 같이 할 수도 있습니다. Intent callIntent = new Intent (Intent.ACTION_CALL); callIntent.setData (Uri.parse ("tel :"+ pnmu)); context.startActivity (callIntent); 변수를 통해 숫자를 보내는 경우 –

10

을 다음과 같은 내 솔루션을 가지고 거기에 어떤 신체 도움 ...

관련 문제