2

I need to call in background in my app, so when the user click a button, it should start calling in the background, the user will know that he is calling, but he wont see the Dialer, he will see the app, to reproduce sounds while calling.

So basically what i want is make a call without exit of the activity

I tryed with a service but it doesnt work

 Intent callIntent = new Intent(Intent.ACTION_CALL);
 callIntent.setData(Uri.parse("tel:123456789"));
 startService (callIntent);

Sorry about my english

D4rWiNS
  • 2,585
  • 5
  • 32
  • 54

2 Answers2

1

Try this one:

Intent callIntent = new Intent(Intent.ACTION_CALL);
 callIntent.setData(Uri.parse("tel:123456789"));
 startActivity(callIntent);

*Notice the startActivity(callIntent), instead of startService(callIntent);.

You can also experiment with ACTION_DIAL, instead of ACTION_CALL. You'll also need this permission, but place it before the Application tag in the AndroidManifest:

<uses-permission android:name="android.permission.CALL_PHONE" />
g00dy
  • 6,752
  • 2
  • 30
  • 43
  • 2
    thx for the answer but i know this, what i want is to do it in the background – D4rWiNS Jul 17 '13 at 06:44
  • Yes, but there's no other way of making phone calls and it was designed like so. So if you want to make a phone call, you do it with an `Intent`, which opens up another activity. – g00dy Jul 17 '13 at 06:49
1

Code Behind:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    call();
}

private void call() {
    try {
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:123456789"));
        startActivity(callIntent);
    } catch (ActivityNotFoundException e) {
        Log.e("sample call in android", "Call failed", e);
    }
}

Manifest.xml
Add..

<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>

Or,

<uses-permission android:name="android.permission.CALL_PRIVILEGED"></uses-permission>

EDIT: Well,tasomaniac made a good point about existing current activity which OP also wants.

So basically what i want is make a call without exit of the activity.

But it is impossible to do anything during call states of telephony interface in android.One possible good solution would be PhoneStateListener to see when the call is ended and then resume your current activity.Some very good solutions are described..

Community
  • 1
  • 1
ridoy
  • 6,274
  • 2
  • 29
  • 60