Rejecting Incoming call in android

前端 未结 6 611
旧巷少年郎
旧巷少年郎 2020-12-01 02:37

I want to reject incoming in android, I have seen so many code from these links.

  1. Android: Taking complete control of phone(kiosk mode), is it possible? How?

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-01 02:58

    In order to intercept your call you just have to:
    1. Make a package named. com.android.internal.telephony;
    2. In this package make a interface file named ITelephony.
    and write this code in that interface file.

    boolean endCall();
    void answerRingingCall();
    void silenceRinger();
    

    Now in your class where you want to intercept the call extend that class to BroadcastReceiver and in onReceive()function write the following code.

    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
       try {
         Class c = Class.forName(tm.getClass().getName());
         Method m = c.getDeclaredMethod("getITelephony");
         m.setAccessible(true);
         telephonyService = (ITelephony) m.invoke(tm);
         Bundle bundle = intent.getExtras();
         String phoneNumber = bundle.getString("incoming_number");
         Log.d("INCOMING", phoneNumber);
         if ((phoneNumber != null)) { 
            telephonyService.endCall();
            Log.d("HANG UP", phoneNumber);
         }
    
       } catch (Exception e) {
         e.printStackTrace();
       }
    

    Thats it.

提交回复
热议问题