2011-09-21 2 views
0

안녕하세요. 활동이있는 애플리케이션을 만들고 싶습니다. 내 활동. 이제 20 초 이내에 응답이 없으면 수신 전화로 시작하고 싶습니다. 제발 도와주세요.방송 수신기에 대해서

+0

당신이 방법을 만들 수 계산 전화가 왔을 때 수신기? 옳은? –

답변

1

먼저 같은 수신기를 등록해야합니다 ..

<receiver android:name=".CustomBroadcastReceiver"> 
    <intent-filter> 
      <action android:name="android.intent.action.PHONE_STATE" />  
    </intent-filter> 
다음

당신이 전화 상태 변경을 수신하도록 등록

.

다음은 사용자의 사양에 맞게 phonestateListener을 확장하고자 할 것입니다. 당신이 당신의 브로드 캐스트 리시버를 만들고 여기에

public class CustomPhoneStateListener extends PhoneStateListener { 



private static final String TAG = "CustomPhoneStateListener"; 

public void onCallStateChange(int state, String incomingNumber){ 
//Here you recieve the phone state being changed and are able to get the number and state. 

switch(state){ 
      case TelephonyManager.CALL_STATE_RINGING: 
        Log.d(TAG, "RINGING"); 
        //Here you could count with for() for 20 seconds and then create a method to do what you want. 
        break; 

...

public class CustomBroadcastReceiver extends BroadcastReceiver { 

private static final String TAG = "CustomBroadcastReceiver"; 

@Override 
public void onReceive(Context context, Intent intent) { 
    Log.v(TAG, "inside"); 
TelephonyManager telephony =  (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); 
    CustomPhoneStateListener customPhoneListener = new CustomPhoneStateListener(); 

telephony.listen(customPhoneListener, PhoneStateListener.LISTEN_CALL_STATE); 


Bundle bundle = intent.getExtras(); 
String phoneNr= bundle.getString("incoming_number"); 
    Log.v(TAG, "phoneNr: "+phoneNr); 

} 

편집 : 그래서 당신은 방송을 시작하려면 같은

public void increment() { 
    if (count < maxCount) count++; 

} 
+0

응답 해 주셔서 감사합니다. 20 초 기다리는 법. – Suyash

+0

for 루프를 사용하여 CALL_STATE_RINGER이 int를 만들고 매번 하나씩 incrementmenet하는 동안 볼 수 있습니다. "int i = 0; increment it i ++ –

+0

또는 while 루프를 사용할 수도 있습니다 –