doulan2827 2014-09-15 18:19
浏览 23

Android Instant Messenger发送语音文件

Hello I made a simple Instant Messenger App based on https://github.com/Pirngruber/AndroidIM 's work. Now I want to send voice files instead of texts. This is how the message is sent:

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);      
}

And then:

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;


}

Im a beginner in android development so I hope you can help me.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度