结束通话Android中 [英] End Call in Android
问题描述
我想结束几秒钟后,一个新的呼出。这是我的code:
公共类电话中延伸活动{
组件名CN;
/ **第一次创建活动时调用。 * /
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
呼叫();
}
私人无效调用(){
尝试 {
意图callIntent =新的意图(Intent.ACTION_CALL);
callIntent.setData(Uri.parse(电话:123456789));
startActivity(callIntent);
CN =新的组件名(getApplicationContext(),Receiver.class);
}赶上(ActivityNotFoundException activityException){
Log.e(拨号,例如,呼叫失败,activityException);
}
}
}
我的接收器类:
公共类接收器扩展的BroadcastReceiver {
公共无效的onReceive(上下文的背景下,意图意图){
如果(intent.getAction()。等于(Intent.ACTION_NEW_OUTGOING_CALL)){
setResultData(空);
}
}
}
我无法中止呼出。我是新来的Android和似乎无法得到这个工作。
在的BroadcastReceiver
类应该被拦截所有来电。检查接收器类在的AndroidManifest.xml
正确注册:
<接收器的Android版本:NAME =接收器的Android版本:出口=真正的机器人:启用=真正的>
<意图过滤器的Android版本:优先级=1>
<作用机器人:名称=android.intent.action.NEW_OUTGOING_CALL/>
<作用机器人:名称=android.intent.action.PHONE_STATE/>
<类机器人:名称=android.intent.category.DEFAULT/>
&所述; /意图滤光器>
< /接收器>
这是说,我不相信这是可能的,取消电话后的 的接收函数完成。我已经试过移动 setResultData(空)
并与几秒钟的延迟一个线程,但我相信这有没有影响的原因是因为其目的已执行呼叫已被启动。
这是可能的,唯一的办法就是让你的手脏与的 PhoneFactory 。已经有许多尝试做到这一点(在没有成功我的知识),并有一个响亮的不这样做!从社区。 P>
I'm trying to end a new outgoing call after few seconds. Here is my code:
public class phonecalls extends Activity {
ComponentName cn;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
call();
}
private void call() {
try {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123456789"));
startActivity(callIntent);
cn = new ComponentName(getApplicationContext(), Receiver.class);
} catch (ActivityNotFoundException activityException) {
Log.e("dialing-example", "Call failed", activityException);
}
}
}
My receiver class is:
public class Receiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
setResultData(null);
}
}
}
I am unable to abort the outgoing call. I'm new to Android and can't seem to get this to work.
The BroadcastReceiver
class should be intercepting all calls. Check if the receiver class is registered correctly in AndroidManifest.xml
:
<receiver android:name="Receiver" android:exported="true" android:enabled="true">
<intent-filter android:priority="1">
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
<action android:name="android.intent.action.PHONE_STATE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
That said, I don't believe that it's possible to cancel the call after the receiver function completes. I've tried moving setResultData(null)
into a thread with a few seconds delay, but I believe the reason this has no effect is because the intent has already been executed and the call has been started.
The only way that this might be possible is getting your hands dirty with internal API calls in PhoneFactory. There have been many attempts to do this (to my knowledge without success), and there is a resounding "do not do this!" from the community.
这篇关于结束通话Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!