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;
}
}
}
}
Related
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.
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; }
}
}
}
I want to make a phone call and after the call ends I want to come back the Activity which started a call.
Code to start a call :
// Start a call
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + phoneNumber));
startActivity(callIntent);
Code to handle coming back to activity :
// Monitor phone call activities
private class PhoneCallListener extends PhoneStateListener {
private boolean isPhoneCalling = false;
String TAG = "PhoneCallListener";
#Override
public void onCallStateChanged(int state, String incomingNumber) {
// If call ringing
if (state == TelephonyManager.CALL_STATE_RINGING) {
Log.d(TAG, "Call ringing, number : " + incomingNumber);
}
// Else if call active
else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
Log.d(TAG, "Call active");
isPhoneCalling = true;
}
// Else if call idle
else if (state == TelephonyManager.CALL_STATE_IDLE) {
Log.d(TAG, "Call idle");
if (isPhoneCalling) {
isPhoneCalling = false;
// Finish native call application to come back to this
// activity
Intent i = new Intent(getIntent());
i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(i);
}
}
}
}
Using finish() does not work. It stays on call application.
How do I come back to the Activity that started a phone call?
i try to write a program for android .I want to make a call with my program and after that recognize the call status. With Flowing Function I can recognize the hang out status and for answering status it doesn’t work.I try this function but it doesn’t work either
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;
}
}
}
}
You can not do that with CALL_STATE_IDLE and CALL_STATE_OFFHOOK.
You have to detect programatically the end of outgoing ringtone...
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;
}
}
}
}
}