2014-09-03 239 views
1

我怎樣才能上傳文件到服務器(一個PHP服務器)沒有瘋狂的驅動器? 我已經嘗試了所有的想法,但我得到這樣的錯誤:包裝 的NoClassDefFoundError期間 Android的重複文件:org.apache.http.entity.ContentTypeAndroid上傳文件到服務器

任何幫助嗎?我不能相信,像這樣的事情normali是完全不可能做到......

我需要一個簡單的:

private class upload extends AsyncTask<Void, Integer, Void> { 
    @Override 
    protected void onPreExecute(){} 
    @Override 
    protected Void doInBackground(Void... params){ 
     try { 
      // bla bla bla 
     }catch(Exception e){} 
     return null; 
    } 
    @Override 
    protected void onPostExecute(Void result){ 
     new register().execute(); 
    } 
} 
+0

Android手機上的Web服務器上的[上傳大文件可能重複](http://stackoverflow.com/questions/3351742/upload-large-files-on-the-web-server-on-android) – 2014-09-03 11:45:18

回答

-1
private String URL_PERMISSION = "http://yourhost.com/yourphppage.php"; 

    /** 
     * Async task to create a new food category 
     * */ 
     private class AddNewCategory extends AsyncTask<String, Void, Void> { 

      boolean isNewCategoryCreated = false; 

      @Override 
      protected void onPreExecute() { 
       super.onPreExecute(); 
       pDialog1 = new ProgressDialog(MainActivity.this); 
       pDialog1.setMessage("Updating Message Status.."); 
       pDialog1.setCancelable(true); 
       pDialog1.show(); 

      } 

      @Override 
      protected Void doInBackground(String... arg) { 

       //String newCategory = arg[0]; 

       // Preparing post params 

       List<NameValuePair> params = new ArrayList<NameValuePair>(); 
       params.add(new BasicNameValuePair("message_status", "0")); 

       //params.add(new BasicNameValuePair("id", "3")); 

       ServiceHandler serviceClient = new ServiceHandler(); 

       String json1 = serviceClient.makeServiceCall(URL_PERMISSION, 
         ServiceHandler.POST, params); 
    //   String json1 = serviceClient.makeServiceCall(URL_Update, 
    //     ServiceHandler.POST, params); 

       Log.d("Update Response: ", "> " + json1); 

       if (json1 != null) { 
        try { 
         JSONObject jsonObj1 = new JSONObject(json1); 
         boolean error = jsonObj1.getBoolean("error"); 
         // checking for error node in json 
         if (!error) { 
          // new category created successfully 
          isNewCategoryCreated = true; 
         } else { 
          Log.e("Update Message Error: ", "> " + jsonObj1.getString("message")); 
         } 

        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 

       } else { 
        Log.e("JSON Data", "Didn't receive any data from server!"); 
       } 


       return null; 
      } 

      @Override 
      protected void onPostExecute(Void result) { 
       super.onPostExecute(result); 
       pDialog1.dismiss(); 
       //new GetContactList().execute(); 
       //populateSpinner(); 
       if (isNewCategoryCreated) { 
        runOnUiThread(new Runnable() { 
         @Override 
         public void run() { 
          // fetching all categoriesList 

         } 
        }); 
       } 
      } 

     } 
+0

請花時間解釋這段代碼。 – 2014-09-03 11:47:47

+0

這是一個愚蠢的JSON,沒有鏈接到我的問題,這涉及到圖片上傳! – 2014-09-05 13:32:52