使用telephonyserivce.endcall Android中结束通话() [英] ending call in android using telephonyserivce.endcall()

查看:176
本文介绍了使用telephonyserivce.endcall Android中结束通话()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序的工作,我想结束呼出。
这是主类

I am working on app where i want to end outgoing call. this is the main class

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

public class phonecalls extends Activity {
/** 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);
} catch (ActivityNotFoundException activityException) {
    Log.e("dialing-example", "Call failed", activityException);
}
}
} 

和outgoingclass是这样

and outgoingclass is this

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;
import com.android.internal.telephony.ITelephony;
import java.lang.reflect.Method;

public class OutgoingCallReceiver extends BroadcastReceiver {

private final String TAG = "CallControl";
Context context;
String incomingNumber;
ITelephony telephonyService;  

@Override
    public void onReceive(Context context, Intent intent) {
    TelephonyManager tm = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE);
    try {
        // Java reflection to gain access to TelephonyManager's
        // ITelephony getter
        Bundle bundle = intent.getExtras();

        if(null == bundle)
                return;

        String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

        Log.i("OutgoingCallReceiver",phonenumber);
        Log.i("OutgoingCallReceiver",bundle.toString());

        String info = "Detect Calls sample application\nOutgoing number: " + phonenumber;


        Toast.makeText(context, info, Toast.LENGTH_LONG).show();

        Log.v(TAG, "Get getTeleService...");
        Class c = Class.forName(tm.getClass().getName());
        Method m = c.getDeclaredMethod("getITelephony");
        m.setAccessible(true);
        telephonyService=(ITelephony) m.invoke(tm);
        telephonyService.endCall();
    } catch (Exception e) {
        e.printStackTrace();
        Log.e(TAG,
                "FATAL ERROR: could not connect to telephony subsystem");
        Log.e(TAG, "Exception object: " + e);
    }       

    }
}

但呼叫没有结束,即使我能够打印没有。呼出启动时显示该广播接收器可以正常使用。

But the call is not ended even though i am able to print no. when outgoing call starts which show broadcasting receiver is working right .

任何建议

推荐答案

是肯定存在双向使用飞行模式或为这个内部电话做到这一点无论是。我用内部电话和code开发我在这里上传 https://github.com/deependersingla/end_calls

Yes definately there is two way to do it either using airplane mode or internal telephony for this . I used internal telephony and code I developed is uploaded here https://github.com/deependersingla/end_calls.

如果你需要更多的东西告诉我,会很乐意提供帮助。

If you need anything more tell me , will be happy to help.

这篇关于使用telephonyserivce.endcall Android中结束通话()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆