android 自己写挂电话,MTK Android 如何自动挂断电话

//拨打电话,并定时60S对方未接听自动挂断

public voidCall()

{

Uri localUri = Uri.parse("tel:" + mPhoneNumber[mCalledIdx]);

Intent call = new Intent(Intent.ACTION_CALL, localUri);

call.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(call);

Log.d(XX, "szsxd caihr sosCall(): mCalledIdx(mPhoneNumberMax) = " + mCalledIdx + "(" + mPhoneNumberMax +")"

+ "; number = " + mPhoneNumber[mCalledIdx]);

timer = new Timer();

timer.schedule(new TimerTask(){

public void run()

{

try {

TelephonyManager telMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);

Method getITelephonyMethod = telMgr.getClass().getDeclaredMethod("getITelephony");

getITelephonyMethod.setAccessible(true);

ITelephony call = (ITelephony)getITelephonyMethod.invoke(telMgr);

call.endCall();

Log.d(XX, "szsxd caihr call.endCall()");

//取消未接显示

//PhoneUtils.getITelephony(telMgr).cancelMissedCallsNotification();

} catch (Exception e) {

Log.d(XX, "szsxd caihr appEndCall():" + e.getMessage());

}

}

}, 60*1000);

}

//自动挂断电话子程序

public void appEndCall(Context context)

{

/* try{

//反射获得系统服务的getService方法对象

Method method = Class.forName("Android.os.ServiceManager")

.getMethod("getService", String.class);

//执行这个方法得到一个IBinder对象

IBinder binder = (IBinder) method.invoke(null, new Object[]{TELEPHONY_SERVICE});

//转换为具体的服务类(ITelephony)接口对象

ITelephony telephony = ITelephony.Stub.asInterface(binder);

//结束通话

telephony.endCall();

}catch(Exception e){

Log.d(XX, "szsxd caihr SOSCallService.e.printStackTrace()");

e.printStackTrace();

}*/

try {

TelephonyManager telMgr = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);

PhoneUtils.getITelephony(telMgr).endCall();

//取消未接显示

//PhoneUtils.getITelephony(telMgr).cancelMissedCallsNotification();

} catch (Exception e) {

Log.d(XX, "szsxd caihr appEndCall():" + e.getMessage());

}

}

/**

* 自动挂断电话系统对象获取

* @author caihr

*/

public static class PhoneUtils

{

public static ITelephony getITelephony(TelephonyManager telMgr) throws Exception

{

Method getITelephonyMethod = telMgr.getClass().getDeclaredMethod("getITelephony");

getITelephonyMethod.setAccessible(true);

return (ITelephony)getITelephonyMethod.invoke(telMgr);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值