本文主要是介绍安卓,来电 接听、挂断,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
示例:
// 执行屏蔽操作private static void DoShield(Context context){TelephonyTool.answerRingingCall(context); // 接听Sleep(3100); // 延时3.1秒TelephonyTool.endCall(context); // 自动挂断return;}
下载
示例应用:https://blog.csdn.net/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();}
这篇关于安卓,来电 接听、挂断的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!