Android Instant Messenger发送语音文件

时间:2014-09-15 18:19:43

标签: php android http webserver

您好我根据https://github.com/Pirngruber/AndroidIM的工作制作了一个简单的Instant Messenger应用程序。 现在我想发送语音文件而不是文本。 这是消息的发送方式:

public String sendMessage(String  username, String  tousername, String message) throws UnsupportedEncodingException 
{           
    String params = "username="+ URLEncoder.encode(this.username,"UTF-8") +
                    "&password="+ URLEncoder.encode(this.password,"UTF-8") +
                    "&to=" + URLEncoder.encode(tousername,"UTF-8") +
                    "&message="+ URLEncoder.encode(message,"UTF-8") +
                    "&action="  + URLEncoder.encode("sendMessage","UTF-8")+
                    "&";        
    Log.i("PARAMS", params);
    return socketOperator.sendHttpRequest(params);      
}

然后:

public String sendHttpRequest(String params)
{       
    URL url;
    String result = new String();
    try 
    {
        url = new URL(AUTHENTICATION_SERVER_ADDRESS);
        HttpURLConnection connection;
        connection = (HttpURLConnection) url.openConnection();
        connection.setDoOutput(true);

        PrintWriter out = new PrintWriter(connection.getOutputStream());

        out.println(params);
        out.close();

        BufferedReader in = new BufferedReader(
                new InputStreamReader(
                        connection.getInputStream()));
        String inputLine;

        while ((inputLine = in.readLine()) != null) {
            result = result.concat(inputLine);              
        }
        in.close();         
    } 
    catch (MalformedURLException e) {
        e.printStackTrace();
    } 
    catch (IOException e) {
        e.printStackTrace();
    }           

    if (result.length() == 0) {
        result = HTTP_REQUEST_FAILED;
    }

    return result;


}

我是android开发的初学者,所以我希望你能帮助我。

0 个答案:

没有答案