各种来电防火墙之类的功能都可以过滤掉黑名单中的来电, 原理是响铃是判断来电号码是否存在于黑名单中, 如果存在则将其挂断.
挂断一个电话在API-10和之前版本中直接调用TelephonyManager对象的endCall方法即可, 但是之后的版本中这个API不再被公开(升级后的Android系统中还存在, 但是在Android SDK中不再提供给开发者* ).
还想忤逆股沟的意思来调用它的话, 用反射. (有两种方法):
- package com.example.hanguptest;
- import java.lang.reflect.Method;
- import android.app.Activity;
- import android.os.Bundle;
- import android.os.IBinder;
- import android.telephony.TelephonyManager;
- import android.view.View;
- import android.widget.Toast;
- import com.android.internal.telephony.ITelephony;
- public class MainActivity extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- public void hangUp1(View v) throws Exception{
- Toast.makeText(getApplicationContext(), "hangUp1", 0).show();
- TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
- Class tmClazz = tm.getClass();
- Method getITelephonyMethod = tmClazz.getDeclaredMethod("getITelephony", null);
- getITelephonyMethod.setAccessible(true);
- ITelephony iTelephony = (ITelephony) getITelephonyMethod.invoke(tm, null);
- iTelephony.endCall();
- }
- /**
- * @param v
- * @throws Exception
- */
- public void hangUp2(View v) throws Exception{
- Toast.makeText(getApplicationContext(), "hangUp1", 0).show();
- Class clazz = Class.forName("android.os.ServiceManager");
- Method getServiceMethod = clazz.getMethod("getService", String.class);
- IBinder iBinder = (IBinder) getServiceMethod.invoke(null, TELEPHONY_SERVICE);
- ITelephony iTelephony = ITelephony.Stub.asInterface(iBinder);
- iTelephony.endCall();
- }
- }
注意:要导入
com/android/internal/telephony/ITelephony.aidl
android/telephony/NeighboringCellInfo.aidl
9707

被折叠的 条评论
为什么被折叠?



