安卓,来电 接听、挂断

示例: 

	// 执行屏蔽操作
	private static void DoShield(Context context)
	{
		TelephonyTool.answerRingingCall(context);	// 接听
		Sleep(3100);								// 延时3.1秒
		TelephonyTool.endCall(context);				// 自动挂断
		return;
	}

 下载

示例应用:https://blog.youkuaiyun.com/scimence/article/details/88894411



package com.sc.tool;

import java.lang.reflect.Method;

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

import com.android.internal.telephony.ITelephony;

/** 电话操作接口,
 * 接听:answerRingingCall、
 * 挂断:endCall、
 * 静音:silenceRinger 
 * */
public class TelephonyTool
{

	/** 获取ITelephony实例对象 */
	public static ITelephony getITelephony(Context context)
	{
		ITelephony itelephony = null;
		
		try
		{
			TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
			
			// 调用TelephonyManager.getITelephony()获取ITelephony实例对象
			// Class c = Class.forName(telephony.getClass().getName());
			Method m = telephony.getClass().getDeclaredMethod("getITelephony");	
			m.setAccessible(true);
			itelephony = (ITelephony) m.invoke(telephony);
		}
		catch (Exception ex)
		{	
			
		}
		
		return itelephony;
	}
	
	/** 挂断 */
	public static boolean endCall(Context context)
	{
		ITelephony I = getITelephony(context);
		try
		{
			return I.endCall();
		}
		catch (Exception ex)
		{
			return false;
		}
	}
	
	/** 接听 */
	public static void answerRingingCall(Context context)
	{
		ITelephony I = getITelephony(context);
		try
		{
			I.answerRingingCall();
		}
		catch (Exception ex)
		{}
	}
	
	/** 静音 */
	public static void silenceRinger(Context context)
	{
		ITelephony I = getITelephony(context);
		try
		{
			I.silenceRinger();
		}
		catch (Exception ex)
		{}
	}
	
}

ITelephony.aidl

package com.android.internal.telephony;

  interface ITelephony 
  {
    boolean endCall();
    void answerRingingCall();
    void silenceRinger();
  }

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值