Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - Sending 2 files to a server
    text
    copied!<p>I am trying to make an android app in which i can take or choose 2 pics from the gallery and send them to a server. The code:</p> <pre><code>private static final int SELECT_PICTURE = 1; private String selectedImagePath; private int TAKE_PHOTO_CODE = 0; private Uri outputFileUri; public void getit() { Intent intentpic= new Intent(); intentpic.setAction(Intent.ACTION_GET_CONTENT); intentpic.setType("image/*"); startActivityForResult(Intent.createChooser(intentpic, "Select Picture"), SELECT_PICTURE); } public void takepic() { final String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/IDandCCD/"; File newdir = new File(dir); newdir.mkdirs(); String file=""; if(but.equals(3)) { file = dir+"ID"+".jpg"; } else if(but.equals(4)) { file = dir+"CCD"+".jpg"; } File newfile = new File(file); try { newfile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } outputFileUri = Uri.fromFile(newfile); Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); startActivityForResult(cameraIntent, TAKE_PHOTO_CODE); } public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { if (requestCode == SELECT_PICTURE) { Uri selectedImageUri = data.getData(); selectedImagePath = getPath(selectedImageUri); //selectedImagePath = selectedImageUri.getPath()+".jpg"; if(but.equals(1)) { id.setText(selectedImagePath); } else if(but.equals(2)) { ccd.setText(selectedImagePath); } } else if(requestCode == TAKE_PHOTO_CODE) { String fname = outputFileUri.getPath(); if(but.equals(3)) { id.setText(fname); } else if(but.equals(4)) { ccd.setText(fname); } } } } @SuppressWarnings(value = { "deprecation" }) public String getPath(Uri uri) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = managedQuery(uri, projection, null, null, null); if(cursor!=null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } else return null; } private class MyAsyncTask extends AsyncTask&lt;String, Void, String&gt; { ProgressDialog pro1; protected void onPostExecute(String result) { pro1.dismiss(); } @Override protected void onPreExecute() { pro1 = ProgressDialog.show(ThirdStep.this, "Loading", "Please wait"); } @Override protected String doInBackground(String... params) { String hdfgs="tgabvds"; HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(params[0]); String responseStr=null; try { MultipartEntity entity = new MultipartEntity(); FileBody pic1=new FileBody(new File(id.getText().toString())); FileBody pic2=new FileBody(new File(ccd.getText().toString())); entity.addPart("idpic", pic1); entity.addPart("ccdpic", pic2); httppost.setEntity(entity); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity=response.getEntity(); responseStr=resEntity.toString(); } catch (Exception e) { Log.e("Debug", "error: " + e.getMessage(), e); } return responseStr; } } </code></pre> <p>But i ran into a problem:</p> <pre><code>08-20 12:45:20.409: D/dalvikvm(2235): DexOpt: couldn't find static field Lorg/apache/http/message/BasicHeaderValueParser;.INSTANCE 08-20 12:45:20.409: W/dalvikvm(2235): VFY: unable to resolve static field 2667 (INSTANCE) in Lorg/apache/http/message/BasicHeaderValueParser; 08-20 12:45:20.482: D/dalvikvm(2235): VFY: replacing opcode 0x62 at 0x001b 08-20 12:45:20.502: D/dalvikvm(2235): DexOpt: couldn't find static field Lorg/apache/http/message/BasicHeaderValueFormatter;.INSTANCE 08-20 12:45:20.528: W/dalvikvm(2235): VFY: unable to resolve static field 2661 (INSTANCE) in Lorg/apache/http/message/BasicHeaderValueFormatter; 08-20 12:45:20.528: D/dalvikvm(2235): VFY: replacing opcode 0x62 at 0x0015 08-20 12:45:22.618: D/dalvikvm(2235): GREF has increased to 201 </code></pre> <p>At first i thought it was because of the imported jar's for MultipartEntity, but i put them in libs folder of the project, and they appear in Android Private Libraries. After i added them i refreshed and cleaned the project. I am doing this in Eclipse, and when i start the app in the emulator, I can take a pic, i can choose a pic from the phone, but when i try to upload it I get the error. If anyone has a suggestion, i would appreciate it.</p> <p>PS I didn't overlook it, it's just that I am not doing anything with the result, yet.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload