开发者

Android: Can you send/receive data along a phonecall?

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 开发者_C百科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");
    }
}


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.

Intent mIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber + ";" + dtmfSequence));

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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜