Android:您可以通过电话发送/接收数据吗?
我正在尝试将一些数据传递到我正在拨打的电话上。 我有什么办法可以做到这一点吗? 我并不真正关心数据的类型(一位就足够了), 只要我能识别它并触发特定的操作。
发送代码:
Intent call = new Intent();
call.setAction(Intent.ACTION_CALL);
call.setData(Uri.parse("tel:" + contact.getNumber()));
call.putExtra("Boolean", true);
startActivity(call);
接收代码:
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null) {
if (extras.getBoolean("Boolean")){
Log.d("BOOL", "true");
} else {
Log.d("BOOL", "false");
}else {
Log.d("BOOL", "nothing");
}
}
I'm trying to pass some data to a phone I'm calling.
Is there any way I can do this?
I don't really care about the type of data (a single bit is enough),
as long as I can identify it and trigger a specific action.
Send code:
Intent call = new Intent();
call.setAction(Intent.ACTION_CALL);
call.setData(Uri.parse("tel:" + contact.getNumber()));
call.putExtra("Boolean", true);
startActivity(call);
Recieve code:
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null) {
if (extras.getBoolean("Boolean")){
Log.d("BOOL", "true");
} else {
Log.d("BOOL", "false");
}else {
Log.d("BOOL", "nothing");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你在那里做的事情是不可能的。当您向另一台设备拨打电话时,您拨打的不一定是 Android 设备。您发送到呼叫意图的布尔值将被该意图读取,而不是发送到呼叫中的其他设备。
如果您想将数据发送到另一台电话设备,您可以发送按键音。这些是按下按钮时发出的声音(例如,如果您给银行打电话,他们要求您按一个客户服务,按两个电话银行等,这些按键会沿着接收器识别的连接发送稍微不同的音调作为“一”和“二”的触摸按键,因此可以执行某些操作)。
您需要向电话发送按键音,并在另一端处理接收按键音。正确的实现将允许两个 Android 手机进行通信,就像发送数据一样。
它们通常也称为 DTMF 音。
上面的代码将随电话发送 DTMF 音。
我不确定如何访问接收器设备上的音频流,因此您必须自己研究一下,以获取流并收听 DTMF 音调。
祝你好运,希望这有帮助!
What you are doing there is not possible. When you make a phone call to another device, it isn't necessarily an Android device you are calling. The boolean you are sending to the call intent is being read by that intent and not sent to the other device in the call.
If you want to send data to another telephone device, you can send up touch tones. These are the sounds made by button presses (So for example, if you ring your bank and they ask you to press one for customer service, two for telephone banking etc, those key presses send a slightly different tone along the connection which the receiver regonises as being a touch press for "one" and "two", so can perform some action).
You would need to send touch tones to the phone call, and also handle recieving them at the other end. Correct implementation will allow the two Android phones to communicate, as if sending data.
They are also commonly referred to as DTMF tones.
The code above will send the DTMF tones with the phone call.
I'm not sure how to access the audio stream on the reciever device, so you would have to look into this yourself, to get hold of the stream and listen for the DTMF tones.
Good luck, hope this helps!