Reputation: 331
I want to be able to make calls from my app. I understand how to make a call from an app. The problem is that I don't want to redirect the user after the call is made.
As far as I understand this code is used to make a call:
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + phonenumber));
startActivity(intent);
The problem is that a user is then redirected to a default caller app(don't know how its called). I want the user to stay in my app when the call is active.
Any suggestions ?
Upvotes: 0
Views: 269
Reputation: 331
I think I found a solution myself.
I used this code to make the call:
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + phonenumber));
startActivity(intent);
Then I made a call state listener which listens for the call to take place. Once the call is initiated i run this code to open my app's activity again:
Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("IN_CALL", true);
context.startActivity(intent);
The call is not canceled and still runs in the background.
I think it's a pretty simple solution to my problem because I don't need to rewrite the caller app and I can still use the basic features of the caller app. Like hanging up, putting my phone to speaker mode, etc.
Upvotes: 1
Reputation: 3031
With this code you do not make call from you app, you start the default app for calling a number. If you do not want to use the default application, you have to implement the phone calling by yourself (which I do not reccomend, by the way, but you can do it if you need to).
Here is the default caller application of android, you have to make something similar (and make it up to date by time).
Also you can register for call made by any other appication by putting this intent-filter in you manifest file:
<activity
android:name="com.test.Call"
android:label="@string/makeCall" >
<intent-filter>
<action android:name="android.intent.action.CALL" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<data android:scheme="tel" />
</intent-filter>
</activity>
Upvotes: 2