结束通话后的通话活动

时间:2014-09-02 12:29:53

标签: android telephonymanager

在我的应用程序中,我希望在结束通话时呼叫活动。该人必须参加电话会议,一旦他进行了对话,他就会结束通话。在这里,我想在结束通话时呼叫活动。我不想在闲置状态下调用活动。在他结束通话之后,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
 {

 }

 }

1 个答案:

答案 0 :(得分:0)

尝试这一点,当电话响铃时将分配的呼叫分配为真,如果已选择,如果呼叫是传入,则将call_attended设置为true。在来电断开后,如果call_attended为true,则启动您的活动。下面的粗略代码:

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;
}