Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.abortoutgoingcall;
- import java.lang.reflect.Method;
- import android.app.Activity;
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.Intent;
- import android.net.Uri;
- import android.os.Bundle;
- import android.telephony.TelephonyManager;
- import android.util.Log;
- import android.widget.Toast;
- import com.android.internal.telephony.ITelephony;
- public class MyReceiver extends BroadcastReceiver{
- Context context = null;
- private ITelephony telephonyService;
- String number;
- String ussd;
- @Override
- public void onReceive(Context context, Intent intent)
- {
- if( intent.getAction().equals( Intent.ACTION_NEW_OUTGOING_CALL ) )
- {
- number = intent.getExtras().getString( Intent.EXTRA_PHONE_NUMBER );
- Log.i( "out1", "number: " + number );
- }
- try
- {
- ussd = "*" + "121";
- if(number.equals(ussd))
- {
- TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
- Class c = Class.forName(telephony.getClass().getName());
- Method m = c.getDeclaredMethod("getITelephony");
- m.setAccessible(true);
- telephonyService = (ITelephony) m.invoke(telephony);
- Toast tag = Toast.makeText(context, "Call is not allowed in the meeting!!!", Toast.LENGTH_LONG);
- tag.setDuration(25);
- tag.show();
- Intent serviceIntent = new Intent(context, testclass.class);
- serviceIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- context.startService(serviceIntent);
- Log.v("out2" , "Dialed Number :"+ number + "USSD :"+ussd);
- telephonyService.silenceRinger();
- telephonyService.endCall();
- }
- else
- {
- Toast.makeText(context, "tp", Toast.LENGTH_LONG);
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- }
- /* i want to block call when user dial *121 like USSD so tried above code but not working but when i remove
- if(number.equals(ussd)) and else it working fine and able to block all outgoing calls and i am developing this app in android 2.1 and tested in many devices like samsung Galaxy and motorola atrix */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement