0
I am using an Async task below to call the webservice helper.
public class Send_reportclaim_Async extends AsyncTask<String, Void, String> {
private ProgressDialog Dialog;
@Override
protected void onPreExecute() {
Dialog = new ProgressDialog(Reportclaim.this);
Dialog.setMessage(Reportclaim.this.getResources().getString(
R.string.loading));
Dialog.setCancelable(false);
Dialog.show();
// Dialog.setContentView(R.layout.progress_dialog);
}
@Override
protected String doInBackground(String... params) {
String result = "";
try {
if (isInternetPresent) {
WebserviceHelper.sendreportclaimdetails(civilid,
imei, policynum, caseno.getText().toString(), dateloss.getText().toString(),policy_rep.getText().toString());
result = "Success";
} else {
result = "Failure";
}
} catch (Exception e) {
result = "Failure";
e.printStackTrace();
}
return result;
}
@Override
protected void onPostExecute(String result) {
// Toast.makeText(getApplicationContext(), "post execute",
// 1).show();
if (result.contentEquals("Success")) {
if (AAAparams.sendmsg.contentEquals("Success")) {
//subview.setVisibility(View.INVISIBLE);
Toast.makeText(getApplicationContext(),
AAAparams.sendmsg.toString(), 1).show();
}
else if (AAAparams.sendmsg.contentEquals("Failure")) {
if ((language.contentEquals(""))
|| (language.contentEquals("en"))) {
// /to do
Toast.makeText(getApplicationContext(), "You FAILED", 1)
.show();
} else if (language.contentEquals("ar")) {
// to do
Toast.makeText(getApplicationContext(), "You FAILED", 1)
.show();
}
}
} else {
showAlert(Reportclaim.this,
getResources().getString(R.string.no_internet), "3");
}
Dialog.dismiss();
}
}
아래 주어진 WebserviceHelper 클래스. JSON 객체를 가져온 후 결과를 가져 오는 동안 디버깅 할 때 예외가 발생합니다.android에서 파일 경로를 사용하여 파일을 업로드하는 방법 파일 경로를 Base64로 변환 한 다음 JSON 배열로 변환하는 방법은 무엇입니까?
public static void sendreportclaimdetails(String civil_id, String imei,
String polno, String caseno, String lossdate,String fileuploads)
throws ClientProtocolException, IOException, JSONException {
String result = null;
JSONObject jObject = null;
try {
METHOD_NAME = "/Dtls";
HttpPost request = new HttpPost(URL + METHOD_NAME);
HttpClient httpclient = new DefaultHttpClient();
List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
/*postParameters.add(new BasicNameValuePair("pImeiNumber",
BaseActivity.doEncrypt(imei)));*/
String[] separated = fileuploads.split(":");
String policy_rep= separated[0];
String reg_book=separated[1];
String Dri_lic=separated[2];
File file = new File(fileuploads);
FileBody fileboady = new FileBody(file);
MultipartEntity reqEntity = new MultipartEntity();
// add file
reqEntity.addPart("pImeiNumber", new StringBody(String.valueOf(BaseActivity.doEncrypt(imei))));
reqEntity.addPart("pPolNo", new StringBody(String.valueOf(polno)));
reqEntity.addPart("pCaseNo", new StringBody(String.valueOf(caseno)));
reqEntity.addPart("pLossDat:", new StringBody(String.valueOf(lossdate)));
reqEntity.addPart("pFileUploads", fileboady);
request.setEntity(reqEntity);
HttpResponse response = httpclient.execute(request);
/*postParameters.add(new BasicNameValuePair("pCivilId", civil_id));
postParameters.add(new BasicNameValuePair("pPolNo:", polno));
postParameters.add(new BasicNameValuePair("pCaseNo:", caseno));
postParameters.add(new BasicNameValuePair("pLossDate", lossdate));
postParameters.add(new BasicNameValuePair("pFileUploads", fileuploads));*/
/*
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(
postParameters);
request.setEntity(entity);
HttpResponse response = getThreadSafeClient().execute(request);*/
entityResponse = response.getEntity();
result = EntityUtils.toString(entityResponse, HTTP.UTF_8);
//Log.e("resultttttttttttttttt", result.toString());
JSONObject object = (JSONObject) new JSONTokener(result)
.nextValue();
} catch (Exception e) {
e.printStackTrace();
System.out.println("svfsdgdfjnhgfkjghkg");
}
}
문자열 pol_rep는 reg_book는 dri_lic는 JSON 배열 후 BASE 64로 변환하고 uploaded.How 될 파일의 경로를 포함한다.
파일 바디와 MultipartEntity 내가 패키지를 추가해야 타입으로 해결 될 수없는 ?? 내가 뭘 추가해야 pakages – zyonneo
@zyonneo : 다음 예제 HTTP를 참조하십시오 //tacticalnuclearstrike.com/2010/01/using-multipartentity-in-android-applications/ \ –
널 포인터 예외 받기 – zyonneo