最近处理一个需要呼叫阻止功能的Android项目,我开始知道要阻止你需要ICollectionView myitemslist = CollectionViewSource.GetDefaultView(mydbcontext.myobject.Local);
权限的呼叫。
虽然权限仅授予系统应用程序,但我想知道Truecaller是如何做到这一点的。据我所知,Truecaller不是一个系统应用程序。
Truecaller背景: 这是一款广泛使用的应用,用于识别来电者信息。它具有阻止垃圾邮件发送者和特定的已知和未知联系人等功能。查找更多here。
如果Truecaller有特殊权限,请提及获取这些权限的过程。
答案 0 :(得分: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
BTW,您的项目中ITelephony.aidl
不是必需的,只是方便,请查看this答案。