如何在Android中挂断电话?我正在开发一个应用程序,其中我们需要的一件事是控制传出呼叫,至少能够从我们的应用程序中阻止它。我尝试过使用Intent.ACTION_CALL现有的活动:Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber)); startActivity(callIntent);但是通过API似乎不允许停止呼叫。你能建议一些解决方法吗?例如:在通话期间启用飞机模式?只是一个例子; 这个黑客对我不起作用。
3 回答
慕容森
TA贡献1853条经验 获得超18个赞
BroadcastReceiver已经提到了在a中捕获拨出呼叫,如果你想在拨号之前结束通话,这绝对是最好的方法。
但是,一旦拨号或通话,该技术就不再适用。我到目前为止挂断的唯一方法是通过Java Reflection完成。由于它不是公共API的一部分,因此您应该小心使用它,而不是依赖它。对Android内部组成的任何更改都将有效地破坏您的应用程序。
Prasanta Paul的博客演示了如何实现它,我在下面总结了这一点。
获取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();
慕雪6442864
TA贡献1812条经验 获得超5个赞
创建
BroadcastReceiver优先级为0的。在BC中拦截
ACTION_NEW_OUTGOING_CALL其onReceive方法的意图setResultData(null)用同样的方法打电话
这将阻止调用启动(只要您的接收者是最后一个处理我认为的意图)
- 3 回答
- 0 关注
- 1039 浏览
添加回答
举报
0/150
提交
取消
