【发布时间】:2016-05-24 12:20:05
【问题描述】:
我记得,Avast 防盗功能允许您设置一个“秘密密码”,您可以拨打该密码以打开 UI。当我拨打它时发生的情况是呼叫没有通过,然后拨号器立即关闭并打开 UI(或者 UI 超出了拨号器活动。我忘记了)。
我以某种方式实现了这一点,但不是呼叫中止,而是在我的活动在它前面时转到后台(绿色状态栏、响铃等)。
当我拨打特定号码时,如何在打开自己的活动时中止呼叫?
关于我的方法的一些代码:
呼叫的广播接收器:
public class OutgoingCallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Match if action is outgoing call.
Intent i = new Intent();
i.setAction(HelperClass.ACTION_NEW_OUTGOINGCALL);
i.setClassName(HelperClass.PACKAGE_NAME, HelperClass.CLASS_NAME_OUTGOING);
i.putExtra(HelperClass.CONTACT_KEY, "contact");
i.putExtra(HelperClass.CLIENT_DEVICE_KEY, "DUMMY");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
// Apparently, this doesn't work
abortBroadcast();
// --------------- FAILED ATTEMPT ---------------------
// if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
// TelephonyManager tm = (TelephonyManager) context
// .getSystemService(Context.TELEPHONY_SERVICE);
// try {
// // Java reflection to gain access to TelephonyManager's
// // ITelephony getter
// Log.v(HelperClass.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);
// }
}
}
}
尝试失败:未找到 ITelephony。失败的尝试来自https://stackoverflow.com/a/5314372/3979290
更新:尝试实施,失败。不知道如何实现:How to hang up outgoing call in Android?
【问题讨论】:
标签: android telephony telephonymanager