0

我想在我的应用程序中阻止拨出呼叫我正在使用以下编码来阻止呼叫

public class MyReceiver extends BroadcastReceiver{

     Context context = null;
     private ITelephony telephonyService;
     String number;
     TelephonyManager telephony;
     String ussd = "*123456";
    @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 );           
     }
     telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
    try 
    {
         String action = intent.getAction();
         if(number.equals(ussd))
         {
              Class c = Class.forName(telephony.getClass().getName());
              Method m = c.getDeclaredMethod("getITelephony"); 
              m.setAccessible(true);
             com.android.internal.telephony.ITelephony telephonyService  = (ITelephony) m.invoke(telephony);
             telephonyService.silenceRinger();
             telephonyService.endCall();
        }
    } 
    catch (Exception e) 
    {
        e.printStackTrace();
    }

}
}

当有人拨打特定的任何号码时,我想阻止呼叫,即我给了*12345。如果我删除此源代码工作正常if(number.equals(ussd)) then i am able to block all outgoing calls but i am trying for particular number please help me to find where am i wrong ?

4

0 回答 0