2

I want to make an application in which once the application starts, it will show two button(start and stop button) and once the user clicks the start button the call function will be blocked for the time period till the user again start the application and click the stop button to stop this function. any help please its urgent

in short I Will tell I want to block the outgoing call from my phone by using this activity only

please is there any way to do so???

Sahil Mahajan Mj
  • 11,033
  • 8
  • 53
  • 100
surya
  • 109
  • 1
  • 4
  • 13
  • better check these links [Link1](http://stackoverflow.com/questions/7595092/how-to-block-outgoing-calls-and-text-sms) [Link2](http://stackoverflow.com/questions/7121508/android-taking-complete-control-of-phone-is-it-possible-how/7121586#7121586) [Link3](http://code.google.com/p/krvarma-android-samples/source/browse/trunk/DetectCalls/src/com/varma/samples/detectcalls/receivers/OutgoingCallReceiver.java) – andy Nov 10 '12 at 06:05

2 Answers2

9

You can block the outgoing call using the setResultData(null) function in the onReceive method of the Broaadcast receiver.

public class BlockOutgoing extends BroadcastReceiver
{
    String number;
    @Override
    public void onReceive(Context context, Intent intent) 
    {
        Log.d("12280", "asdasNumber is-->> " + number);
        number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        setResultData(null);
        Toast.makeText(context, "Outgoing Call Blocked" , 5000).show();

    }
}

In the manifest file, you need to register the receiver like this,

<receiver
            android:name=".BlockOutgoing"
            android:label="@string/app_name" >
            <intent-filter android:priority="1">

<action android:name="android.intent.action.NEW_OUTGOING_CALL" />

            </intent-filter>
        </receiver>

Also define the permission to intercept the outgoing call,

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

Edit- To unregister a broadcast receiver, follow this link

Community
  • 1
  • 1
Sahil Mahajan Mj
  • 11,033
  • 8
  • 53
  • 100
  • thanx it works,, sorry but can u tell me how to cancle this broadcast now – surya Nov 10 '12 at 09:02
  • yeh i tried this but it didnt work for me so is there any other way to do so let me explain u my problem... here i have tow button in when i click on 1st button it should start the broadcast and stop the out going calls and again when i run again my application and if i click on second button then the broadcast receiver should start or stop i guess and my call should be start going again – surya Nov 11 '12 at 09:40
0

public class BlockOutgoing extends BroadcastReceiver {

String number;
@SuppressLint("WrongConstant")
@Override
public void onReceive(Context context, Intent intent)
{
    // Log.d("12280", "asdasNumber is-->> " + number);
    number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
    setResultData(null);
    Toast.makeText(context, "Outgoing Call Blocked" , 5000).show();

}

}

   <receiver
        android:name=".BlockOutgoing"
        android:label="@string/app_name" >
        <intent-filter android:priority="1">
            <action android:name="android.intent.action.NEW_OUTGOING_CALL" />

        </intent-filter>
    </receiver>