禁用来电通知

时间:2014-12-18 01:34:14

标签: java android

我一直在编写一些Android代码,涉及拒绝某些电话号码的呼叫,并且已经到了可以拦截来电的地方,将其与特定号码进行比较,然后拒绝它。一旦我检测到它想要阻止它的数字,我也在使用SILENT_MODE设置,因此没有声音。但是,在呼叫完全停止之前,呼叫通知仍会在屏幕上显示一两秒钟。有谁知道如何防止这种情况?这甚至可能吗?如何立即将呼叫转移到语音邮件消息然后删除消息?我还假设可能有一个工作可以使屏幕变黑但这将是一个糟糕的用户体验。我在我的实现中使用ITelephony Java类。任何建议将不胜感激!!!!!!以下是我目前的代码:

   public class PhoneCallReceiver extends BroadcastReceiver
   {
    private ITelephony telephonyService;

    @Override
    public void onReceive(Context context, Intent intent)
    {
        TelephonyManager telephony = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);

        // TODO Auto-generated method stub
        Bundle extras = intent.getExtras();
        if (extras != null)
        {
            String state = extras.getString(TelephonyManager.EXTRA_STATE);

            if (state.equals(TelephonyManager.EXTRA_STATE_RINGING))
            {
                String phoneNumber = extras
                        .getString(TelephonyManager.EXTRA_INCOMING_NUMBER);

                // Will eventually retrieve a list from shared preferences
                // instead of contacts.
                contactsMap = mypackage.com.util.ContactsUtil
                        .getPhoneContacts(context);
                Log.e("DEBUG", phoneNumber);

                // testing purposes...
                if (phoneNumber.equals("4133972057"))
                {
                    AudioManager aManager = (AudioManager) context
                            .getSystemService(Context.AUDIO_SERVICE);
                    aManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
                    Class c;
                    try
                    {
                        c = Class.forName(telephony.getClass().getName());
                        Method m = c.getDeclaredMethod("getITelephony");
                        m.setAccessible(true);
                        telephonyService = (ITelephony) m.invoke(telephony);


                        telephonyService.endCall();
                    }
                    catch (ClassNotFoundException e)
                    {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    catch (NoSuchMethodException e)
                    {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    catch (IllegalAccessException e)
                    {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    catch (IllegalArgumentException e)
                    {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    catch (InvocationTargetException e)
                    {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    catch (RemoteException e)
                    {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                }

            }

        }
    }
}

0 个答案:

没有答案