2014-09-02 39 views
0

在我的申請中,我想在結束通話時致電活動。該人必須參加該呼叫,並且一旦他進行了談話,他將結束該呼叫。在這裏,我想在該人結束通話時致電該活動。我不想在空閒狀態下調用活動。在他結束通話之後,callReceived變爲false,callEnded變爲true。一旦通話結束,我無法查看我的活動。請給我一個想法來實現這種情況。提前致謝。結束通話後致電活動

這是我的代碼。

public static boolean ring=false; 
public static boolean callReceived=false; 
public static boolean callEnded=false; 
public void telephonyRegister(Context context, Intent intent) 
{ 
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);       
ctx=context; 
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
     TelephonyManager.EXTRA_STATE_IDLE)) { 
    callEnded =true; 
    if(ring==true&&callReceived==false) 
    { 
     Toast.makeText(context, "THIS IS MISSED CALL FROM"+phoneNumber, Toast.LENGTH_LONG).show(); 
     String smsmessage = "We will contact you shortly"; 
     SmsManager smsManager = SmsManager.getDefault(); 
     smsManager.sendTextMessage(phoneNumber, null, "Hi"+" "+smsmessage, null, null); 
     Log.i("sms",smsmessage); 
     Toast.makeText(context, "SMS sent.", 
     Toast.LENGTH_LONG).show();  
    } 
    Toast.makeText(context,"Recording Stopped", Toast.LENGTH_SHORT).show(); 
    stopRecording(); 


    } 
else if(intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
     TelephonyManager.EXTRA_STATE_OFFHOOK)) 
{ 
    callReceived = true; 
    Toast.makeText(context,"Recording Started", Toast.LENGTH_SHORT).show(); 
    callEnded =false; 
    if(callReceived==false&&callEnded==true) 
    { 
     Intent myIntent = new Intent(ctx, PushRemarkstoServer.class); 
     ctx.startActivity(myIntent); 

    } 
} 
else if(intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
     TelephonyManager.EXTRA_STATE_RINGING)){ 
    ring = true; 
    phoneNumber = intent.getStringExtra("incoming_number");   
    new Handler().postDelayed(new Runnable() { 
     @Override 
     public void run() { 
      // TODO Auto-generated method stub 
      Intent intent = new Intent(ctx,ProjectDailogActivity.class); 
      intent.putExtra("incoming_number",phoneNumber); 
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      ctx.startActivity(intent); 

     } 
    }, 2000); 

} 
else 
{ 

} 

} 

回答

0

試試這個,當電話響起分配callringing爲真,如果挑,如果呼叫是呼入然後設置call_attended爲真。在傳入呼叫斷開之後,如果call_attended爲真,那麼開始你的活動。下面粗代碼:

String state = bundle.getString(TelephonyManager.EXTRA_STATE); 
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) { 
iscallringing=true; 
} 
else if(state.equals(TelephonyManager.CALL_STATE_OFFHOOK&&iscallringing){ 
call_attended=true; 
iscallringing=false; 
} 
else if(state.equals(TelephonyManager.EXTRA_STATE_IDLE&&call_attended){ 
//start your activity here 
call_attended=false; 
iscallringing=false; 
} 
+0

沒有它不工作 – user3764346 2014-09-02 12:56:51

+0

你有沒有聲明這些iscallringing,call_attended全球varible。嘗試在每個if語句中放入日誌,以便在電話呼叫階段知道這些變量的值 – Psypher 2014-09-02 12:59:57