Reputation: 191
I have the following code :
public static void dialNumber(Context context, String phoneNumber)
{
_logger.info("Calling " + phoneNumber);
Intent intent = new Intent(ACTION_CALL, Uri.fromParts("tel", phoneNumber, null));
context.startActivity(intent);
}
This starts a call to the given phoneNumber. I want to put some logic when this call finishes. how can i do that. How to know if the call finishes. I tried using startActivityForResult, but i cant call this function on a Context.
Thanks
Upvotes: 0
Views: 1528
Reputation: 9429
check BroadcastReceiver
receiver and system's broadcast messages. This kind of events (starting call, ending call, etc) are usually sent by broadcast message. And, if you have receiver, you can get and do whatever you want. for instance, android.intent.action.PHONE_STATE
might work for you.
http://androidexample.com/Introduction_To_Broadcast_Receiver_Basics/index.php?view=article_discription&aid=60&aaid=85
I think you get get information that you want through intent.getExtras
public void onReceive(Context context, Intent intent) {
intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
int state = 0;
if(stateStr.equals(TelephonyManager.EXTRA_STATE_IDLE)){
state = TelephonyManager.CALL_STATE_IDLE;
}
else if(stateStr.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){
state = TelephonyManager.CALL_STATE_OFFHOOK;
}
else if(stateStr.equals(TelephonyManager.EXTRA_STATE_RINGING)){
state = TelephonyManager.CALL_STATE_RINGING;
}
}
Upvotes: 1
Reputation: 427
Maybe this is worth checking out. You can use startActivityForResult to get some kinda feedback from a started activity once it is done doing things.
Upvotes: 0