15

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

  1. Android:完全控制手机(kiosk模式),有可能吗?如何?

  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

但是我还是做不到,谁能告诉我简单的步骤怎么做?

4

6 回答 6

17

为了拦截您的电话,您只需:
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();
   }

而已。

于 2013-02-22T20:38:24.243 回答
5

提供适当的权限并添加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....");

        }
于 2015-02-12T05:56:03.143 回答
2

您将需要一个带有意图过滤器的广播接收器,我认为 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)

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

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.PROCESS_INCOMING_CALLS" />

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

快乐编码。

于 2013-02-21T21:09:40.253 回答
1

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

Android 来电拦截

于 2017-04-26T14:11:41.483 回答
1

在其中创建一个接口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();
            }
        }

在清单中添加必要的权限

于 2016-08-08T06:09:46.050 回答
0

如果您要构建一个自助服务终端应用程序,那么我建议您获取通知设置并将设备设置为“请勿打扰”模式。

var mNotificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

mNotificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_NONE)
于 2020-04-16T07:45:00.350 回答