2014-09-02 75 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