This post is describing that how to make a call from the Android phone using Intent.ACTION_CALL.
Start a activity with as follows and pass your telephone number
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + <your tel number>));
activity.startActivity(callIntent);
To check the state of the phone call and actions setup a call listener as follows
private class EndCallListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if(TelephonyManager.CALL_STATE_RINGING == state) {
Log.i("contactus", "RINGING, number: " + incomingNumber);
}
if(TelephonyManager.CALL_STATE_OFFHOOK == state) {
Log.i("contactus", "OFFHOOK");
}
if(TelephonyManager.CALL_STATE_IDLE == state) {
if (incomingNumber.equals(szListentelNumber) == true) {
Intent i = activity.getBaseContext().getPackageManager()
.getLaunchIntentForPackage(
activity.getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
activity.startActivity(i);
}
Log.i("contactus", "IDLE" + incomingNumber);
}
}
}
public void setUpCallListener(String szTelNumber) {
this.szListentelNumber = szTelNumber;
EndCallListener callListener = new EndCallListener();
TelephonyManager mTM = (TelephonyManager)activity.getSystemService(Context.TELEPHONY_SERVICE);
mTM.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);
}
Enjoy the coding with Android and if you like this simple post please provide your feedback.
Thanks
Creative Android Apps
nice blog
ReplyDeleteandroid training in bangalore
ios training in bangalore
machine learning online training
I was reading through some of your content on this internet site and I believe this site is really instructive! Keep putting up. ipad mockups
ReplyDelete