Advertisement
Guest User

test

a guest
Apr 6th, 2012
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. package com.abortoutgoingcall;
  2.  
  3. import java.lang.reflect.Method;
  4. import android.app.Activity;
  5. import android.content.BroadcastReceiver;
  6. import android.content.Context;
  7. import android.content.Intent;
  8. import android.net.Uri;
  9. import android.os.Bundle;
  10. import android.telephony.TelephonyManager;
  11. import android.util.Log;
  12. import android.widget.Toast;
  13. import com.android.internal.telephony.ITelephony;
  14.  
  15. public class MyReceiver extends BroadcastReceiver{
  16.  
  17. Context context = null;
  18. private ITelephony telephonyService;
  19. String number;
  20. String ussd;
  21. @Override
  22. public void onReceive(Context context, Intent intent)
  23. {
  24. if( intent.getAction().equals( Intent.ACTION_NEW_OUTGOING_CALL ) )
  25. {
  26. number = intent.getExtras().getString( Intent.EXTRA_PHONE_NUMBER );
  27. Log.i( "out1", "number: " + number );
  28. }
  29. try
  30. {
  31. ussd = "*" + "121";
  32. if(number.equals(ussd))
  33. {
  34. TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
  35. Class c = Class.forName(telephony.getClass().getName());
  36. Method m = c.getDeclaredMethod("getITelephony");
  37. m.setAccessible(true);
  38. telephonyService = (ITelephony) m.invoke(telephony);
  39. Toast tag = Toast.makeText(context, "Call is not allowed in the meeting!!!", Toast.LENGTH_LONG);
  40. tag.setDuration(25);
  41. tag.show();
  42. Intent serviceIntent = new Intent(context, testclass.class);
  43. serviceIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  44. context.startService(serviceIntent);
  45.  
  46. Log.v("out2" , "Dialed Number :"+ number + "USSD :"+ussd);
  47. telephonyService.silenceRinger();
  48. telephonyService.endCall();
  49. }
  50. else
  51. {
  52. Toast.makeText(context, "tp", Toast.LENGTH_LONG);
  53. }
  54.  
  55. }
  56. catch (Exception e)
  57. {
  58. e.printStackTrace();
  59. }
  60.  
  61. }
  62. }
  63. /* i want to block call when user dial *121 like USSD so tried above code but not working but when i remove
  64. 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