How to send an audio file from Android phone to computer?

Asked

Viewed 751 times

10

I’m working on an Android app that records the phone call on a mobile device.

I just need to send a copy of the audio file to the computer via TCP/IP. I already have a function that sends text to the computer. But how to send an audio file ?

On the computer I already have a server made in Delphi that communicates with the mobile and vice versa. I also know how to do, in Delphi, to receive the file on the computer. I just do not know how to make the code to send from the mobile.

Someone has an idea?

1 answer

2

Asynchronously ....

    Socket socket  = null;
    BufferedInputStream bufferedInputStream = null;

    try {
        socket = new Socket("192.168.198.1", 8901);
        bufferedInputStream = new BufferedInputStream(socket.getInputStream());
        int counter = 0;
        String path = "/mnt/sdcard/ad.wav";
        FileOutputStream fileOutputStream = new FileOutputStream(new File(path));
        byte jj[] = new byte[1024];
        while ((counter = bufferedInputStream.read(jj, 0, 1024)) != -1) {
            fileOutputStream.write(jj, 0, counter);
        }
        fileOutputStream.close();            
        socket.close();
    } catch (Exception e) {
        e.printStackTrace();            
    }

source

I only organized the code suggested in the comments by checkmate.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.