A.G.
A.G.

Reputation: 2119

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?

Upvotes: 2

Views: 3131

Answers (3)

nikhil_salunke
nikhil_salunke

Reputation: 150

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;
            }

        }
    }
}

Upvotes: 0

A.G.
A.G.

Reputation: 2119

To always make calls using the Phone app, add this line:

    callIntent.setClassName("com.android.phone", "com.android.phone.OutgoingCallBroadcaster");

Upvotes: 2

Cilenco
Cilenco

Reputation: 7117

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.

Upvotes: 0

Related Questions