我记得,Avast防盗功能可让您设置一个“秘密密码”,您可以拨打该密码以打开UI。当我拨打电话时,发生的情况是呼叫未通过,然后拨号程序立即关闭,UI打开(或者UI超出了Dialer活动。我忘记了)。
我以某种方式实现了此功能,但是在我的活动进行到前面的同时,它不会转到呼叫中断,而是转到后台(绿色状态栏,正在响铃的电话等)。
拨打特定号码时,如何在打开自己的活动时中止通话?
我的方法的一些代码:
广播接收器:
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
更新:尝试实施,失败。不确定如何实现:如何在Android中挂断电话?
还查看了:如何在固定的秒数后中止拨出电话?
更新:添加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>
...
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句