【问题标题】:Block incoming calls阻止来电
【发布时间】:2010-02-25 14:06:40
【问题描述】:

我的 VoiP 客户端想在我自己的通话进行时阻止所有来电。有没有可能以某种方式做到这一点?

【问题讨论】:

    标签: android phone-call callblocking


    【解决方案1】:

    是的,您可以阻止来电。使用此代码

     String phonestate = bundle.getString(TelephonyManager.EXTRA_STATE);
    
     try 
        {
            if (TelephonyManager.EXTRA_STATE_RINGING.equalsIgnoreCase(phonestate)) 
            {
                try 
                {
                    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
                    Class c = Class.forName(tm.getClass().getName());
                    Method m = c.getDeclaredMethod("getITelephony");
                    m.setAccessible(true);
                    telephonyService = (com.android.internal.telephony.ITelephony) m.invoke(tm);
                }
                catch (Exception e) 
                {
                    e.printStackTrace();
                }
    
                if (prefStatus != null) 
                {
                    if (count == 1) 
                    {
                        telephonyService.endCall();
                        String prefLoginemail = myloginpref.getString("emailid", null);
                        System.out.println(printdata + " prefLoginemail :: "+ prefLoginemail);
    
                        Global.mNotificationManager = (NotificationManager) mxcontext.getSystemService(Context.NOTIFICATION_SERVICE);
                        notifyDetails = new Notification(com.CellPhoneTerror.R.drawable.icon1,"CellPhoneTerror!", System.currentTimeMillis());
                        myIntent = PendingIntent.getActivity(mxcontext, 0, new Intent(mxcontext, clsHomePage.class), 0);
    
                        notifyDetails.setLatestEventInfo(mxcontext,"You Got a Call from Blocked Number.", "",myIntent);
                        notifyDetails.flags |= Notification.FLAG_AUTO_CANCEL;
                        Global.mNotificationManager.notify(Global.SIMPLE_NOTFICATION_ID,notifyDetails);
    
                    }
                }
            }
            if (prefIncomingBlock.equals("true")) 
            {
                if (TelephonyManager.EXTRA_STATE_IDLE.equalsIgnoreCase(phonestate)) 
                {
                    if (count == 0) 
                    {
                        System.out.println("if Cellphoneterror:"+ Global.clsIncomingNum);
                        Intent block = new Intent(context, dialogbox1.class);
                        block.setFlags(intent.FLAG_ACTIVITY_NEW_TASK);
                        context.startActivity(block);
                    }
                }
            }
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }
    

    谢谢。

    【讨论】:

    • -1 我认为提问者想知道如何做到这一点很漂亮。
    • 对不起朋友,但是我的网络坏了,所以我不能在这里举个例子。无论如何感谢您的评论。
    • 你怎样才能避免延迟,有时在它被阻塞之前会响一两声?
    【解决方案2】:

    不使用当前的 SDK 否,您可以监控来电并让用户选择使用您的应用程序而不是本机应用程序接听

    【讨论】:

    • 如何通过意向选择器向用户提供选择要回答的应用程序?谢谢你的帮助。
    • 是的,您可以注册以侦听该意图并在该意图上启动您的应用程序
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-04
    • 1970-01-01
    相关资源
    最近更新 更多