问题描述
我有两部手机其中被配对,并通过蓝牙连接。如何以编程方式在一个电话结束检查其他手机是否越来越来电?我应该使用这个特定配置文件,也就是说,PBAP或HFP?如果是的话,我是多么做呢?
I have two phones which are paired and connected via bluetooth. How to programmatically check at one phone's end whether the other phone is getting an incoming call? Should I use a particular profile for this, that is, PBAP or HFP? If yes, how I am to do this?
有一次,我发现这一点,如果我想通过所连接的手机接听电话,应该怎么实现呢?
Once I detect this, if I want to receive the incoming call via the connected phone, how should I implement that?
推荐答案
下载免提配置文件的PDF。它可以很容易地。它提供了有关HFP如何工作并在由HFP通信支持的命令所有细节。没有关于此的API。
正如eliasj说,你需要实现HFP和当两个手机得到连接,你可以在它们之间通过AT指令控制。
假设你有1手机,这是Android设备和第二个电话Android或任何设备,他们都连接在HFP。
我没有完成code,但我可以建议你一些AT命令 -
1.使用 AT + CIND?命令,你可以阅读其他手机的指示灯的状态。
2.要启用指示灯状态变化的报告,你需要使用 AT + CMER = 3,0,0,1 命令。
3.一旦你得到有效的响应AT + CMER命令,就可以使用AlarmManager,将启动一个服务,它连续读取蓝牙套接字的输入流。
4.因为步骤2中,如果第二个电话是有任何来电,蓝牙套接字的输入流将包含 RING 作为警报。
我已经使用的服务实现一个Runnable。下面是一个示例code步4.-
Download Hands Free Profile pdf. It is available easily. It provides you all details about how HFP works and AT commands supported by HFP for communication. No APIs available for this.
As eliasj said, you need to implement HFP and when two phones get connected, you can communicate between them via AT commands.
Suppose you have 1st phone which is Android device and 2nd phone Android or any device and they both are connected over HFP.
I don't have complete code but I can suggest you some AT commands -
1. Using AT+CIND? command you can read indicator status of other phone.
2. To enable reporting for Indicator status change, you need to use AT+CMER=3,0,0,1 command.
3. Once you get valid response from 'AT+CMER' command, you can use AlarmManager that will start a service which continuously reads the input stream of Bluetooth Socket.
4. Because of step 2., if the 2nd phone is having any incoming call, the input stream of Bluetooth Socket will contains RING as an alert.
I have used service implementing a Runnable. Here is a sample code for step 4.-
public void run()
{
try
{
// Get input and output streams from Bluetooth socket.
m_oInputStream = m_oBluetoothSocket.getInputStream();
m_oOutputStream = m_oBluetoothSocket.getOutputStream();
// Read input stream for +CIEV response is given or not.
byte[] buffer = new byte[200];
int nNumberOfBytesRead = m_oInputStream.read(buffer);
String strResponse = new String(buffer).trim();
if(true == strResponse.contains("RING"))
{
// Contains RING Alert. Answer the call.
// Start Activity for handling Incoming Call.
Intent oIncomingCallActivityIntent = new Intent(getApplicationContext(), IncomingCallActivity.class);
oIncomingCallActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
getApplicationContext().startActivity(oIncomingCallActivityIntent);
// Stop service.
stopSelf();
}
}
catch(Exception e)
{
// Log the error.
}
}
您需要实现acivity处理来电。它会接受或拒绝来电。要接受来电的 AT + ATA 使用命令。您将收到OK从第二个电话的响应。
我希望这会帮助你。
You need to implement acivity that handles incoming call. It will accept or reject call. To accept incoming call AT+ATA command is used. You will receive "OK" as a response from 2nd phone.
I hope this will help you.
这篇关于如何在一个电话查询对方电话是否收到来电?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!