tags:

views:

3896

answers:

8

Hi,

I am developing an application where one of the things we need is to control the outgoing call, at least to be able to stop it from our application.

For now I tried using Intent.ACTION_CALL to use existing activity:

Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber)); 
startActivity(callIntent);

But stopping the call seems to be disallowed by default API.

Can you suggest some workaround?

For example, enabling airplane mode during the call :) Just an example, this hack didn't work for me. :)

Thanks a lot!

Tilek

+5  A: 

Considering the potential for wonderful mischief I would be surprised if this is allowed.

This thread says flatly that the API cannot end a call. Others have tried.

Pat
Then how they did it in [tCallBlocking Lite](http://www.taosoftware.co.jp/en/android/callblockinglite/)?
an0
+2  A: 
  1. Create a BroadcastReceiver with a priority of 0.
  2. In the BC intercept the ACTION_NEW_OUTGOING_CALL intent in its onReceive method
  3. call setResultData(null) in the same method

This will prevent the call from initiating (as long as your receiver is the last to process the intent I think)

A: 

Hi can get an example on how to set a number for dialing automaticaly via API- is there such option at all

ilana
A: 

Terminating the call is possible. TextMe4Callback on the Android market does this.

Julian Misler
A: 

android.provider.Settings.System.putInt(getContentResolver(), android.provider.Settings.System.AIRPLANE_MODE_ON, 1);

Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); intent.putExtra("state", 1); sendBroadcast(new Intent("android.intent.action.AIRPLANE_MODE")); sendBroadcast(intent); android.provider.Settings.System.putInt(getContentResolver(), android.provider.Settings.System.AIRPLANE_MODE_ON, 0);

intent.putExtra("state", 0); sendBroadcast(new Intent("android.intent.action.AIRPLANE_MODE")); sendBroadcast(intent);

Gung Shi Jie
Sledgehammer, meet nut.
Christopher
A: 
Denis Souza
A: 

Very GOOD, Gung Shi Jie ! It works , in addition the android.permission.WRITE_SETTINGS need to be set in Manifest. Thank You Very Much !

But only for Android 2.2 , earlier platforms do not interrupt the call. What to do in 2.1 and earlier ?

Gung Shi Jie , You are only person in Universe, really knowing Android secrets! Most users here just guess. Gung Shi Jie , can you give example working on Android 2.1 platform?

Tony
Click the "up" arrow to register your approval, and add comments via the "Add comment" button, rather than posting a new "answer".
Christopher
+1  A: 

For Ilana:

public class ilanasReceiver extends BroadcastReceiver {
  public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
      if (getResultData()!=null) {
     String number = "123456";
     setResultData(number);
      }
    }
  }
}

In addition in Manifest put in package section:

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

That is all.

Tony