阻止在没有单个环的android中的来电

时间:2017-03-26 15:05:03

标签: java android

虽然这段代码我可以阻止来电,但问题是它在断开时间之前响了几秒钟,我怎么能直接断开电话而不用单铃声。

public class IncomingCallsReceiver extends BroadcastReceiver {
private Context context;
private static int CALLSHIELD_ID = 1982;
private static final String TAG = "Phone call";
private ITelephony telephonyService;

@Override
public void onReceive(Context context, Intent intent) {
    Log.i("Log","coming");
    this.context = context;
    String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
    if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
        TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        Bundle bundle = intent.getExtras();
        String incomingNumber = bundle.getString("incoming_number");
        Cursor cursor;
        if (G.savePreferences.getString("modef", "0").equals("0")) {
            switch (G.savePreferences.getString("mode", "2")) {
                case "0":
                    break;
                case "1":
                    try {
                        Class c = Class.forName(telephony.getClass().getName());
                        Method m = c.getDeclaredMethod("getITelephony");
                        m.setAccessible(true);
                        telephonyService = (ITelephony) m.invoke(telephony);
                        telephonyService.endCall();
                            G.lDbHeper.setlog(incomingNumber, time(), date());
                        if (G.savePreferences.getString("notification", "false") == "true") {
                            showNotification(incomingNumber);
                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                    break;
            }
        }
    }
}

0 个答案:

没有答案