How to filter incomming calls (blacklist) - no reflection

冷暖自知 提交于 2019-12-10 10:39:50

问题


I was wondering if there is a way that I can filter (block) incoming calls on Android (consider 2.1 and up). I found solutions using reflection, but it seem not to be very clean and reliable solution. Is there any standard or google recommended way to do that?

UPDATE: Anyone?


回答1:


use the following broadcast receiver to get the incoming phone number and compare it with the numbers that are in your created filter list

@Override
public void onReceive(Context context, Intent intent) {
    Bundle extras = intent.getExtras();
    if (extras != null) {
        String state = extras.getString(TelephonyManager.EXTRA_STATE);
        Log.w("DEBUG", state);
        if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
            String phoneNumber = extras
                    .getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
            Toast.makeText(context, phoneNumber, 2000).show();
            Log.w("DEBUG", phoneNumber);
        }
    }
}

Hope it will help. You need to create a list of numbers in blacklist by your application's User interface.



来源:https://stackoverflow.com/questions/11535666/how-to-filter-incomming-calls-blacklist-no-reflection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!