简体   繁体   中英

INTENT.ACTION_CALL in background

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

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" />

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..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM