общественный класс, кроме распространяется AsyncTask { личное MyProgressDialog pDialog;
@Override
protected void onPreExecute() {
pDialog = new MyProgressDialog(Send_message.this);
pDialog.setCancelable(false);
pDialog.show();
super.onPreExecute();
}
@Override
protected String doInBackground(String... paramss) {
try {
String json = messagesend.sendmeesage("Your Url",params);
JSONObject jsonobject = new JSONObject(json);
String result = jsonobject.getString("result");
if (result.equals("TRUE")) {
return "true";
}
System.out.println("json is" + json);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return "false";
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
pDialog.dismiss();
}
}
// для отсылки файлов общественного класса messagesendwithhttp {
private String page;
public String sendmeesage(String url, List<NameValuePair> nameValuePairs)throws ClientProtocolException, IOException
{
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(url);
try {
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
for (int index = 0; index < nameValuePairs.size(); index++)
{
if (index == 0 || index == 1)
{
// If the key equals to "image", we use FileBody to transfer
// the data
entity.addPart(nameValuePairs.get(index).getName(), new StringBody(nameValuePairs.get(index).getValue()));
} else {
// Normal string data
if(nameValuePairs.get(index).getValue().equals("") || nameValuePairs.get(index).getValue().toString().equals(null))
{
entity.addPart(
nameValuePairs.get(index).getName(),
new StringBody(nameValuePairs.get(index).getValue()));
}
else
{
entity.addPart(nameValuePairs.get(index).getName(),
new FileBody(new File(nameValuePairs.get(index)
.getValue())));
}
}
}
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost, localContext);
HttpEntity resEntity = response.getEntity();
if (resEntity != null)
{
page = EntityUtils.toString(resEntity);
System.out.println("PAGE :" + page);
}
} catch (IOException e) {
e.printStackTrace();
}
return page;
}
}
enter code here
Я хочу, чтобы загрузить файл как текстовый файл, изображения, другие приложения к серверу БД, а не сообщения – doubter