我正在开发一个应用程序,其中我们需要的一件事是控制传出调用,至少能够从我们的应用程序中阻止它。
我尝试使用现有 Activity 中的 Intent.ACTION_CALL
:
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber));
startActivity(callIntent);
但似乎不允许通过 API 停止调用。
您能提出一些解决方法吗?
例如:通话中开启飞行模式?只是一个例子;这个 hack 对我不起作用。
最佳答案
已经提到在 BroadcastReceiver
中捕获拨出电话,如果您想在拨号前结束通话,这绝对是最好的方法。
但是,一旦拨号或通话,该技术就不再有效。到目前为止,我遇到的唯一挂断方法是通过 Java Reflection .由于它不是公共(public) API 的一部分,您应该小心使用它,而不是依赖它。对 Android 内部构成的任何更改都会有效地破坏您的应用程序。
Prasanta Paul's blog demonstrates如何实现,我总结如下。
获取ITelephony
对象:
TelephonyManager tm = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
try {
// Java reflection to gain access to TelephonyManager's
// ITelephony getter
Log.v(TAG, "Get getTeleService...");
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
com.android.internal.telephony.ITelephony telephonyService =
(ITelephony) m.invoke(tm);
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG,
"FATAL ERROR: could not connect to telephony subsystem");
Log.e(TAG, "Exception object: " + e);
}
结束通话:
telephonyService.endCall();
关于android - 如何挂断Android中的拨出电话?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/599443/