我想在我的应用程序中阻止传出呼叫我正在使用以下编码来阻止呼叫
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 ?