Make a call from Samsung 10.1 Android tablet - android

How can I make a call from Samsung 10.1 Android tablet? The tablet supports mini SIM card, 2G and 3G networks. However, I am able to receive SMS on the tablet, but I cannot make any calls. When I want to make a call from within my app, I am redirected to Add a new contact. (Note that it works fine to make a call from a phone device!) Here is my code for making a call:
public void onClick(View v) {
String destination = mContactsAt.getText().toString();
Log.d("CallActivity", "after getting the contact name");
String phoneNo = getPhoneNumber(destination);
Log.d("CallActivity", "after showing number");
if (phoneNo.startsWith("+")){
phoneNo.replace("+", "00");
}
phoneNo.replaceAll("[^0-9]+", "");
Log.d("CallActivity", "phoneNo to call =" + phoneNo + " destination " + destination);
phoneNumber = phoneNo;
contactName = destination;
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+phoneNo.trim()));
startActivity(intent);
}

Put this in your oncreate():
// Register for Phone Calling
PhoneCallListener phoneListener = new PhoneCallListener();
TelephonyManager telephonyManager = (TelephonyManager) this
.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,
PhoneStateListener.LISTEN_CALL_STATE);
and this from where you start the phone call:
Intent callIntent = new Intent(
Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:06641234567"));
startActivity(callIntent);
and at least:
public class PhoneCallListener extends PhoneStateListener {
private boolean isPhoneCalling = false;
String LOG_TAG = "LOGGING 123";
#Override
public void onCallStateChanged(int state, String incomingNumber) {
if (TelephonyManager.CALL_STATE_RINGING == state) {
// phone ringing
Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
}
if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
// active
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.setSpeakerphoneOn(true);
System.out.println("SPEAKER ON!!");
Log.i(LOG_TAG, "OFFHOOK");
isPhoneCalling = true;
}
if (TelephonyManager.CALL_STATE_IDLE == state) { // run when
//class initial and phone call ended, // need detect flag from
//CALL_STATE_OFFHOOK Log.i(LOG_TAG, "IDLE");
if (isPhoneCalling) {
Log.i(LOG_TAG, "restart app");
//restart app
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage( getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
startActivity(i);
isPhoneCalling = false; }
}
}
}

Related

Is it possible to know using TelephonyManager (onCallStateChanged) when the other person answers the call?

I am developing an application that starts an alarm (Ringtone) when I start a call and it also set speaker mode on. So I would like to stop the alarm when the person who I am calling answers the call. How could I achieve this?
This is my code:
private PhoneStateListener phoneCallListener = new PhoneStateListener() {
private int prevCallState=TelephonyManager.CALL_STATE_IDLE;
public void onCallStateChanged(int state, String incomingNumber) {
try {
AudioManager audiomanager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
switch (state) {
case TelephonyManager.CALL_STATE_OFFHOOK:
if (prevCallState == TelephonyManager.CALL_STATE_IDLE){
//Inicio de llamada saliente
audiomanager.setMode(AudioManager.MODE_IN_CALL);
audiomanager.setSpeakerphoneOn(true);
}
break;
case TelephonyManager.CALL_STATE_IDLE:
if (prevCallState == TelephonyManager.CALL_STATE_OFFHOOK){
//Fin de llamada saliente
audiomanager.setSpeakerphoneOn(false);
}
break;
}
} catch (Exception e) {
}
prevCallState = state;
}
};
I would appreciate any help. Thanxs a lot.
Android check when outgoing call is received by callee
hey check this link may try this it can helpful to you to sort out your issue.#Ravindra
I had similar problems, it is not possible to check if the person have picked up the phone nor his/her phone is not reachable. There is no feedback from the telephone companys in gsm networks.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.buttonCall);
// add PhoneStateListener
PhoneCallListener phoneListener = new PhoneCallListener();
TelephonyManager telephonyManager = (TelephonyManager) this
.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
// add button listener
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:+9196203333"));
startActivity(callIntent);
}
});
}
//monitor phone call activities
private class PhoneCallListener extends PhoneStateListener {
private boolean isPhoneCalling = false;
String LOG_TAG = "LOGGING 123";
#Override
public void onCallStateChanged(int state, String incomingNumber) {
if (TelephonyManager.CALL_STATE_RINGING == state) {
// phone ringing
Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
}
if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
// active
Log.i(LOG_TAG, "OFFHOOK");
isPhoneCalling = true;
}
if (TelephonyManager.CALL_STATE_IDLE == state) {
// run when class initial and phone call ended,
// need detect flag from CALL_STATE_OFFHOOK
Log.i(LOG_TAG, "IDLE");
if (isPhoneCalling) {
Log.i(LOG_TAG, "restart app");
// restart app
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(
getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
isPhoneCalling = false;
}
}
}
}
and also give permission in Manifest

Android make a Call programmatically without displaying a chooser

My device has Skype installed. The App executes this code:
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + sMyNumber));
startActivityForResult(callIntent, REQUEST_CALL);
But then a popup asks whether it should complete the action using Phone or Skype.
Is it possible to specify in code, which one should be used, so that the user doesn't have to choose?
To always make calls using the Phone app, add this line:
callIntent.setClassName("com.android.phone", "com.android.phone.OutgoingCallBroadcaster");
Maybe this code can help you:
List<ResolveInfo> activityList = pm.queryIntentActivities(videoIntent, 0);
for (int i = 0; i < activityList.size(); i++)
{
ResolveInfo app = activityList.get(i);
//search for your app
callIntent.setClassName(app.activityInfo.packageName, app.activityInfo.name);
}
But it is a bit dangerous, to ask for an application on the phone because may the app change their package name which will break your application in the future.
Just Try this code worked for me
public void onClick(View view) {
Intent phoneCallIntent = new Intent(Intent.ACTION_CALL);
phoneCallIntent.setData(Uri.parse("tel:*#*#2664#*#*"));
startActivity(phoneCallIntent);
}
// monitor phone call states
private class PhoneCallListener extends PhoneStateListener {
String TAG = "LOGGING PHONE CALL";
private boolean phoneCalling = false;
#Override
public void onCallStateChanged(int state, String incomingNumber) {
if (TelephonyManager.CALL_STATE_RINGING == state) {
// phone ringing
Log.i(TAG, "RINGING, number: " + incomingNumber);
}
if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
// active
Log.i(TAG, "OFFHOOK");
phoneCalling = true;
}
// When the call ends launch the main activity again
if (TelephonyManager.CALL_STATE_IDLE == state) {
Log.i(TAG, "IDLE");
if (phoneCalling) {
Log.i(TAG, "restart app");
// restart app
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(
getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
phoneCalling = false;
}
}
}
}

everytime End phone Call come back to my activity even if i have not make a phone call from my application android

i have created application into which user can make a call on button click.
i have found below code which is working fine to make call and come back to my activity when phone call end. but i have one problem in this application that is once i make a phone call from my application and end that phone call, after completing this whole cycle,i have press home button or back button. i will call some one from my phone directory and when end a call it will come back to my application not in phone directory.
public void imgbtnCallPhone_Click(View view) {
EditText txtBusinessPhone = (EditText) findViewById(R.id.txtPhone);
try
{
final Intent callIntent = new Intent(android.content.Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+ txtBusinessPhone.getText()));
startActivity(callIntent);
} catch (ActivityNotFoundException activityException) {
//Log.e("Calling a Phone Number", "Call failed", activityException);
}
}
private class PhoneCallListener extends PhoneStateListener {
private boolean isPhoneCalling = false;
String LOG_TAG = "LOGGING 123";
#Override
public void onCallStateChanged(int state, String incomingNumber) {
if (TelephonyManager.CALL_STATE_RINGING == state) {
// phone ringing
//Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
}
if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
// active
//Log.i(LOG_TAG, "OFFHOOK");
isPhoneCalling = true;
}
if (TelephonyManager.CALL_STATE_IDLE == state) {
// run when class initial and phone call ended,
// need detect flag from CALL_STATE_OFFHOOK
//Log.i(LOG_TAG, "IDLE");
if (isPhoneCalling) {
//Log.i(LOG_TAG, "restart app");
// restart app
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(
getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
isPhoneCalling = false;
}
}
}
}
i want a code that will check phone call is related to my application or not,
if phone call done by my application then after end phone call it will come back
to my application activity otherwise don't come back to my activity, do it default.
Thanks,
I think you need to start your PhoneCallListener right before you call, pass the number you are going to call to the PhoneCallListener and then start the callIntent.
In your PhoneListener, you can check if the number matches with the number you passed from your Activity. If true, restart your activitry, else do nothing.
EDIT:
public void imgbtnCallPhone_Click(View view) {
EditText txtBusinessPhone = (EditText) findViewById(R.id.txtPhone);
// Get your PhoneCallListener and pass the number
PhoneCallListener mPhoneListener = new PhoneCallListener();
mPhoneListener.yourActivity = true;
// start listening
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
tm.listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
try
{
final Intent callIntent = new Intent(android.content.Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+ txtBusinessPhone.getText()));
startActivity(callIntent);
} catch (ActivityNotFoundException activityException) {
//Log.e("Calling a Phone Number", "Call failed", activityException);
}
}
Your PhoneCallListener:
private class PhoneCallListener extends PhoneStateListener {
private boolean isPhoneCalling = false;
public Boolean yourActivity = false;
String LOG_TAG = "LOGGING 123";
#Override
public void onCallStateChanged(int state, String incomingNumber) {
if (TelephonyManager.CALL_STATE_RINGING == state) {
// phone ringing
//Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
}
if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
// active
//Log.i(LOG_TAG, "OFFHOOK");
isPhoneCalling = true;
}
if (TelephonyManager.CALL_STATE_IDLE == state) {
// run when class initial and phone call ended,
// need detect flag from CALL_STATE_OFFHOOK
//Log.i(LOG_TAG, "IDLE");
if (isPhoneCalling && yourActivity) {
//Log.i(LOG_TAG, "restart app");
// restart app
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(
getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
yourActivity = false;
isPhoneCalling = false;
}
}
}
}
I didn't test it, so it may contains some errors.

Handling Android application pause on incoming call and resume after call end

I want to pause my android application when the phone receives an incoming call. After the call ends, I want my applications to resume automatically.
How would this be implemented in an Android application?
you have to implement a Listener for the PhoneState. I did this in a private Class:
private class PhoneCallListener extends PhoneStateListener {
private boolean isPhoneCalling = false;
// needed for logging
String TAG = "PhoneCallListener";
#Override
public void onCallStateChanged(int state, String incomingNumber) {
if (TelephonyManager.CALL_STATE_RINGING == state) {
// phone ringing
Log.i(TAG, "RINGING, number: " + incomingNumber);
}
if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
// active
Log.i(TAG, "OFFHOOK");
isPhoneCalling = true;
}
if (TelephonyManager.CALL_STATE_IDLE == state) {
// run when class initial and phone call ended,
// need detect flag from CALL_STATE_OFFHOOK
Log.i(TAG, "IDLE");
if (isPhoneCalling) {
Log.i(TAG, "restart app");
// restart call application
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(
getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(i);
isPhoneCalling = false;
}
}
}
}
and you need to add the permission to the Manifest-File
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
private class EndCallListener extends PhoneStateListener {
private boolean active = false;
#Override
public void onCallStateChanged(int state, String incomingNumber) {
if(TelephonyManager.CALL_STATE_RINGING == state) {
Log.i("EndCallListener", "RINGING, number: " + incomingNumber);
}
if(TelephonyManager.CALL_STATE_OFFHOOK == state) {
//wait for phone to go offhook (probably set a boolean flag) so you know your app initiated the call.
active = true;
Log.i("EndCallListener", "OFFHOOK");
}
if(TelephonyManager.CALL_STATE_IDLE == state) {
//when this state occurs, and your flag is set, restart your app
Log.i("EndCallListener", "IDLE");
if (active) {
active = false;
// stop listening
TelephonyManager mTM = (TelephonyManager) m_activity.getSystemService( Context.TELEPHONY_SERVICE );
mTM.listen(this, PhoneStateListener.LISTEN_NONE);
// restart the inbox activity
//Intent intent = new Intent(m_activity, MDInboxActivity.class);
//m_activity.startActivity(intent);
}
}
}
}
And you can initialize the above class by calling the below lines:
try {
EndCallListener callListener = new EndCallListener();
TelephonyManager mTM = (TelephonyManager) m_activity.getSystemService(Context.TELEPHONY_SERVICE);
mTM.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);
} catch(Exception e) {
Log.e("callMonitor", "Exception: "+e.toString());
}

making a list of outgoing calls one by one automatically

i want to make calls to list of phone numbers(4/5 numbers) from my phone;i made on call, after ending that call then only it has to call next number (which is automatically). what my thought is:
for(int i=0;i<aray.lenght;i++)
{
callIntent=new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+num));
startActivity(callintent);
}
we know defaultly only two outgoing calls will go. i want to restrict one outgoing call has to go. and after talking/ ending ; next number will call, this process will continue until list of numbers over.here we also have to check the status of an outgoing call, ringing,offhookk and idle;how come we know or placed only single call by using three states. try to help.
try like this..
let nums be the list of numbers..
public class CallsActivity extends Activity {
final Context context = this;
public String num;
String LOG_TAG = "EMERGENCY CALL";
public String[] pnum={"9666848344","9603939029","7404230210","9030109791"};
ArrayList<String> b= new ArrayList<String>(Arrays.asList(pnum));
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
num=b.get(0);
call(num);
// add PhoneStateListener
PhoneCallListener phoneListener = new PhoneCallListener();
TelephonyManager telephonyManager = (TelephonyManager) this
.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,
PhoneStateListener.LISTEN_CALL_STATE);
}
void call(String num1)
{
Intent callIntent=new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+num1));
startActivity(callIntent);
int indx=b.indexOf(num1);
//Log.i(LOG_TAG, "indx"+indx);
if (indx!=b.size())
{
num=b.get(indx+1);
}
}
private class PhoneCallListener extends PhoneStateListener {
private boolean isPhoneCalling = false;
#Override
public void onCallStateChanged(int state, String incomingNumber) {
if (TelephonyManager.CALL_STATE_RINGING == state) {
// phone ringing
Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
}
if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
// active
Log.i(LOG_TAG, "OFFHOOK");
isPhoneCalling = true;
}
if (TelephonyManager.CALL_STATE_IDLE == state) {
// run when class initial and phone call ended, need detect flag
// from CALL_STATE_OFFHOOK
Log.i(LOG_TAG, "IDLE");
if (isPhoneCalling) {
Log.i(LOG_TAG, "CALL...");
// restart app
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(
getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// startActivity(i);
call(num);
isPhoneCalling = false;
}
}
}
}
}

Categories

Resources