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);
        }
    } 



你可能感兴趣的:(exception,timer,android,service,MTK,电话)