【问题标题】:How do I abort a call and close the dialer after launching my activity?启动我的活动后,如何中止呼叫并关闭拨号器?
【发布时间】: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?

还看过:How to abort an outgoing call after fixed seconds?

【问题讨论】:

    标签: android telephony telephonymanager


    【解决方案1】:

    更新:将setResultData(null); 添加到广播接收器有效。 它立即结束了通话。

    示例:

    public class OutgoingCallReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            // Immediately cancels the call since this sets the number to null.
            setResultData(null);
    
            // Launch activity here/other stuff you want to do
            // Example:
            //     Intent i = new Intent(context, MyActivity.class);
            //     i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            //     context.startActivity(i);
        }
    }
    

    清单:

    ...
            <receiver
                android:name=".OutgoingCallReceiver"
                android:enabled="true"
                android:exported="true">
                <intent-filter android:priority="2147483647">
                    <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
                </intent-filter>
            </receiver>
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-18
      • 1970-01-01
      相关资源
      最近更新 更多