在android中拒绝来电

我想在android中拒绝传入,我从这些链接中看到了很多代码。

  1. Android:完全掌控手机(自助终端模式),有可能吗? 怎么样?

  2. 如何在android中以编程方式拒绝调用

  3. http://androidsourcecode.blogspot.in/2010/10/blocking-incoming-call-android.html

  4. http://androidbridge.blogspot.com/2011/05/how-to-answer-incoming-call-in-android.html?showComment=1361478035090#c5468022990217431781

但是我仍然无法做到,有人可以通过简单易行的步骤告诉我该怎么做?

    为了拦截你的电话,你只需要:
    1.制作一个名为的包裹。 com.android.internal.telephony;
    2.在此包中创建一个名为ITelephony的接口文件。
    并在该接口文件中编写此代码。

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

    现在,在您想要拦截调用的类中,将该类扩展为BroadcastReceiver并在onReceive()函数中编写以下代码。

     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(); } 

    而已。

    提供适当的权限并添加ITelephony.java文件

     private void declinePhone(Context context) throws Exception { try { String serviceManagerName = "android.os.ServiceManager"; String serviceManagerNativeName = "android.os.ServiceManagerNative"; String telephonyName = "com.android.internal.telephony.ITelephony"; Class telephonyClass; Class telephonyStubClass; Class serviceManagerClass; Class serviceManagerNativeClass; Method telephonyEndCall; Object telephonyObject; Object serviceManagerObject; telephonyClass = Class.forName(telephonyName); telephonyStubClass = telephonyClass.getClasses()[0]; serviceManagerClass = Class.forName(serviceManagerName); serviceManagerNativeClass = Class.forName(serviceManagerNativeName); Method getService = // getDefaults[29]; serviceManagerClass.getMethod("getService", String.class); Method tempInterfaceMethod = serviceManagerNativeClass.getMethod("asInterface", IBinder.class); Binder tmpBinder = new Binder(); tmpBinder.attachInterface(null, "fake"); serviceManagerObject = tempInterfaceMethod.invoke(null, tmpBinder); IBinder retbinder = (IBinder) getService.invoke(serviceManagerObject, "phone"); Method serviceMethod = telephonyStubClass.getMethod("asInterface", IBinder.class); telephonyObject = serviceMethod.invoke(null, retbinder); telephonyEndCall = telephonyClass.getMethod("endCall"); telephonyEndCall.invoke(telephonyObject); } catch (Exception e) { e.printStackTrace(); Log.d("unable", "msg cant dissconect call...."); } 

    你需要一个带有意图filter的广播接收器我觉得ACTION_ANSWER

    有关它的更多详细信息: http : //developer.android.com/reference/android/content/Intent.html#ACTION_ANSWER

    您可以使用清单文件或registerReceiver方法注册它

    更多信息: http : //developer.android.com/reference/android/content/Context.html#registerReceiver (android.content.BroadcastReceiver,android.content.IntentFilter)

    您还需要在清单文件中指定适当的权限。

         

    您提供的链接非常好。 你只需要更多的耐心:)

    快乐的编码。

    com.android.internal.telephony创建一个接口并命名为

     interface ITelephony { /** * Demonstrates some basic types that you can use as parameters * and return values in AIDL. */ void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString); boolean endCall(); void silenceRinger();strong text void answerRingingCall(); } // then catch the incoming call intent and call below method if (intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER) != null) { number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); Toast.makeText(context, "INCOMING call catched: ", Toast.LENGTH_SHORT).show(); disconnectPhoneItelephony(mContext) } private void disconnectPhoneItelephony(Context context) { ITelephony telephonyService; TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); try { Class c = Class.forName(telephony.getClass().getName()); Method m = c.getDeclaredMethod("getITelephony"); m.setAccessible(true); SessionManager.getInstance(context).setBlockStatusAllow("BLOCKED"); telephonyService = (ITelephony) m.invoke(telephony); telephonyService.silenceRinger(); telephonyService.endCall(); } catch (Exception e) { e.printStackTrace(); } } 

    在Manifest中添加必要的权限

    这是阻止所有来电的最佳教程,您可以对其进行自定义以阻止仅选定号码的来电。

    Android来电呼叫阻止