【问题标题】:How truecaller blocks incoming callstruecaller 如何阻止来电
【发布时间】:2018-03-28 17:39:38
【问题描述】:

最近在做一个需要呼叫阻止功能的Android项目,我知道要阻止呼叫你需要MODIFY_PHONE_STATE权限。

虽然权限仅授予系统应用程序,但我想知道 Truecaller 是如何做到的。据我所知,Truecaller 不是系统应用。

Truecaller 背景:这是一款广泛使用并以识别来电者信息而闻名的应用程序。它具有阻止垃圾邮件发送者和特定已知和未知联系人等功能。查找更多here

如果 Truecaller 有特殊权限,请尽可能说明获取这些权限的过程。

【问题讨论】:

  • 如果您首先解释一下真正的 Truecaller 是什么以及它的作用,它可能会有所帮助。它还不够出名,您可以参考并期望我们知道。
  • 你有解决办法吗?
  • 嘿@Astha,我实际上没有找到任何解决方案,或者您可以说我停止寻找解决方案。这是一个似乎很有帮助的答案stackoverflow.com/questions/51085831/…

标签: android android-permissions


【解决方案1】:

广播接收器

    <receiver  android:name=".CallBarring">
        <intent-filter  android:priority="100" >
            <action android:name="android.intent.action.PHONE_STATE" />
        </intent-filter>
    </receiver

监听来电和来电TelephonyManager.getITelephony().endCall()

import java.lang.reflect.Method;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;

import com.android.internal.telephony.ITelephony;

// Extend the class from BroadcastReceiver to listen when there is a incoming call
public class CallBarring extends BroadcastReceiver
{
    // This String will hold the incoming phone number
    private String number;

    @Override
    public void onReceive(Context context, Intent intent)
    {
        // If, the received action is not a type of "Phone_State", ignore it
        if (!intent.getAction().equals("android.intent.action.PHONE_STATE"))
            return;

            // Else, try to do some action
        else
        {
            // Fetch the number of incoming call
            number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);

            // Check, whether this is a member of "Black listed" phone numbers stored in the database
            if(MainActivity.blockList.contains(new Blacklist(number)))
            {
                // If yes, invoke the method
                disconnectPhoneItelephony(context);
                return;
            }
        }
    }

    // Method to disconnect phone automatically and programmatically
    // Keep this method as it is
    @SuppressWarnings({ "rawtypes", "unchecked" })
    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);
            telephonyService = (ITelephony) m.invoke(telephony);
            telephonyService.endCall();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

完整示例github

顺便说一句,你的项目中ITelephony.aidl不是必需的,只是为了方便,看看this的答案。

【讨论】:

  • 嗯,你没有指定需要的版本
  • 不一样。他们不会结束通话。因为来电者仍然听到电话铃声..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多