gpt4 book ai didi

android - 使用 telephonyserivce.endcall() 在 android 中结束通话

转载 作者:太空狗 更新时间:2023-10-29 15:14:06 26 4
gpt4 key购买 nike

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

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

}
}

但即使我能够打印 no,通话仍未结束。当拨出电话开始时,表明广播接收器工作正常。

任何建议

最佳答案

是的,肯定有两种方法可以使用飞行模式或内部电话来做到这一点。我使用内部电话,我开发的代码上传到这里 https://github.com/deependersingla/end_calls .

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

关于android - 使用 telephonyserivce.endcall() 在 android 中结束通话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14092141/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com