【问题标题】:ending call in android using telephonyserivce.endcall()使用 telephonyserivce.endcall() 在 android 中结束通话
【发布时间】:2012-12-30 15:57:11
【问题描述】:

我正在开发要结束拨出电话的应用程序。 这是主要课程

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 是这样的

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);
    }       

    }
}

但即使我可以打印不,通话也没有结束。当拨出电话开始时,显示广播接收器工作正常。

任何建议

【问题讨论】:

  • 终于完成了,所以任何需要帮助的人都可以问..很乐意提供帮助
  • 你能帮我吗?我需要一个可以使用任何技术结束来自特定号码的呼叫的工作版本。我需要 2.3.3+ 设备上的工作版本你能帮我吗?

标签: android telephony telephonymanager


【解决方案1】:

是的,当然有两种方法可以使用飞行模式或内部电话。我使用内部电话,我开发的代码在这里上传https://github.com/deependersingla/end_calls

如果您需要更多信息,请告诉我,我们很乐意提供帮助。

【讨论】:

  • @deepender Singla 你上传到你的 github 上的代码会阻止传入呼叫或传出呼叫你能解释一下吗?你能否解释一下我们必须以哪种格式提供呼叫阻止的号码如果我要阻止的号码是 0345xxxxxxx 我应该将它传递给这样的意图还是我输入这样的号码 92345XXXXXXX 你能解释一下吗?
  • 这个项目不会阻塞任何号码,它只是在几秒钟后结束通话,它会给出指定秒数的未接来电。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-19
  • 2014-03-03
  • 1970-01-01
  • 2011-08-17
  • 1970-01-01
相关资源
最近更新 更多