Android 通话结束后的通话活动
在我的应用程序中,我希望在结束调用时调用活动。此人必须参加通话,一旦通话结束,他将结束通话。在这里,我想在对方结束通话时调用该活动。我不想调用处于空闲状态的活动。在他结束通话后,callReceived变为false,callEnded变为true。通话结束后,我无法查看我的活动。请给我一个实现此场景的想法。提前谢谢 这是我的密码Android 通话结束后的通话活动,android,telephonymanager,Android,Telephonymanager,在我的应用程序中,我希望在结束调用时调用活动。此人必须参加通话,一旦通话结束,他将结束通话。在这里,我想在对方结束通话时调用该活动。我不想调用处于空闲状态的活动。在他结束通话后,callReceived变为false,callEnded变为true。通话结束后,我无法查看我的活动。请给我一个实现此场景的想法。提前谢谢 这是我的密码 public static boolean ring=false; public static boolean callReceived=false; public
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
{
}
}
尝试此方法,当电话铃响时,将callringing指定为true,如果已接听且来电正在接听,则将call_attended设置为true。稍后,在来电断开后,如果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;
}
您是否声明这些是呼叫,呼叫作为全球变量。尝试将日志放入每个if语句中,以了解在电话呼叫阶段这些变量的值