【问题标题】:END CALL through a Button通过按钮结束通话
【发布时间】:2014-04-14 11:02:05
【问题描述】:

我正在尝试通过一个按钮结束通话。通话结束仅在少数手机上正常工作。我如何让它在所有手机中都能正常工作?

在少数电话上,通话根本不会被切断?

这是我尝试过的:

点击 END CALL 会调用以下内容:

 TelephonyManager telephony = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);

    try 
    {
        // Java reflection to gain access to TelephonyManager's
        // ITelephony getter
        Class c = Class.forName(telephony.getClass().getName());
        Method m = c.getDeclaredMethod("getITelephony");
        m.setAccessible(true);
        com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke(telephony);
        telephonyService.endCall();
        finish();

        timeSwapBuff += timeInMilliseconds;
        customHandler.removeCallbacks(updateTimerThread);
    }
    catch (Exception e) 
    {
        e.printStackTrace();
        Log.e("Error", "FATAL ERROR: could not connect to telephony subsystem");
        Log.e("Error", "Exception object: " + e);
    }

让我知道如何解决这个问题?

谢谢!

【问题讨论】:

标签: android call


【解决方案1】:
/**
 * Reject button click listener will reject the incoming call.
 */
private class RejectCallOnClickListener implements OnClickListener {
    @Override
    public void onClick(View v) {
        Log.d(tag, "OnRejectButton: " + "Reject OnClick");
        ignoreCall();
        exitCleanly();
    }
}

/**
 * ignore incoming calls
 */
private void ignoreCall() {
    if (USE_ITELEPHONY)
        ignoreCallAidl();
    else
        ignoreCallPackageRestart();
}
/**
 * AIDL/ITelephony technique for ignoring calls
 */
private void ignoreCallAidl() {
    try {
        // telephonyService.silenceRinger();

        telephonyService.endCall();
    } catch (RemoteException e) {
        e.printStackTrace();
        Log.d(tag, "ignoreCall: " + "Error: " + e.getMessage());

    } catch (Exception e) {
        e.printStackTrace();
        Log.d(tag, "ignoreCall" + "Error: " + e.getMessage());

    }
}
/**
 * package restart technique for ignoring calls
 */
private void ignoreCallPackageRestart() {
    ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    am.restartPackage("com.android.providers.telephony");
    am.restartPackage("com.android.phone");
}
/**
 * cleanup and exit routine
 */
private void exitCleanly() {
    unHookReceiver();
    this.finish();

}

【讨论】:

  • 谢谢,但是 unHookReceiver();, USE_ITELEPHONY 是什么?我收到错误消息?
  • private void unHookReceiver() { if (r != null) { unregisterReceiver(r); if(GetProximityPreference("EnableReceiveByProximity")) { mySensorManager.unregisterListener(proximitySensorEventListener); mySensorManager.unregisterListener(lightSensorEventListener);我的传感器管理器 = 空; FileUtils.appendLog(FileUtils.GetCurrentDateTime() + "功耗日志结束"); FileUtils.appendLog("---------------------------------------------------------- ---"); } r = 空; } }
【解决方案2】:

在iTelephony界面下载iTelephony make

并使用此代码

            TelephonyManager tm = (TelephonyManager) CallActivity.this.getSystemService(Context.TELEPHONY_SERVICE);
            Class c = null;
            try {
                c = Class.forName(tm.getClass().getName());
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            Method m = null;
            try {
                m = c.getDeclaredMethod("getITelephony");
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            }
            m.setAccessible(true);
            Object telephonyService = null; // Get the internal ITelephony object
            try {
                telephonyService = m.invoke(tm);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
            try {
                c = Class.forName(telephonyService.getClass().getName()); // Get its class
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            try {
                m = c.getDeclaredMethod("endCall"); // Get the "endCall()" method
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            }
            m.setAccessible(true); // Make it accessible
            try {
                m.invoke(telephonyService); // invoke endCall()
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-24
    • 1970-01-01
    • 2011-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多