0
我正在開發一個消息聊天應用程序。我已經瀏覽了Telegram Android App的代碼,但沒有看到他們如何在聊天中發送圖片和視頻。如果您可以解釋該方法或爲此提供任何參考,這將非常有幫助。Telegram如何在Android應用程序中發送圖像和視頻?
TIA
我正在開發一個消息聊天應用程序。我已經瀏覽了Telegram Android App的代碼,但沒有看到他們如何在聊天中發送圖片和視頻。如果您可以解釋該方法或爲此提供任何參考,這將非常有幫助。Telegram如何在Android應用程序中發送圖像和視頻?
TIA
您可以使用來自Android應用多內容發送任何類型的文件。你需要包括你的build.gradle
compile 'org.apache.httpcomponents:httpmime:4.3.6'
compile 'org.apache.httpcomponents:httpcore:4.3.3'
private void sendImage(final String fileString, String fileMessageId)
{
Bitmap bitmap;
DataOutputStream dos = null;
String sResponse = null;
bitmap = BitmapFactory.decodeFile(fileString);
File sourceFile = new File(fileString);
String upLoadServerUri = WSConfig.UPLOAD_FILE_URL;
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(upLoadServerUri);
try {
MultipartEntity entity = new MultipartEntity();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
entity.addPart("files",
new FileBody(sourceFile));
httpPost.setEntity(entity);
HttpResponse response;
try {
response = httpClient.execute(httpPost);
BufferedReader reader = new BufferedReader(
new InputStreamReader(
response.getEntity().getContent(), "UTF-8"));
sResponse = reader.readLine();
} catch (IOException e1) {
e1.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
我想發送圖像作爲字節本身沒有上傳到任何服務器。 –
您可以通過Base64字符串 –
發送它我會嘗試它。謝謝:) –