无法从签名的apk中的webservice读取

时间:2015-12-11 07:59:41

标签: android

签署apk后,代码无法从Web服务中读取。我试图调试,发现BufferedReader没有读取任何行。根据其他stackoverflow问题中的一些答案,我已经关闭了progaurd,但仍然没有好处。这只发生在签名的apk中。

 public class LoanRatesWS extends AsyncTask<String, String, ArrayList<LoanRatesBn>> {

    HttpURLConnection connection = null;
    BufferedReader reader = null;
    InputStream in;
    String line;
    StringBuffer buffer = new StringBuffer();
    ProgressDialog progressDialog;
    int httpStatus;
    boolean isTimeout = false;


    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        progressDialog = new ProgressDialog(MainActivity.this);
        Resources resources = getResources();
        String loadingMessage = resources.getString(R.string.loadingMessage);
        Utilities.startProgressDialog(progressDialog, loadingMessage);
    }

    @Override
    protected ArrayList<LoanRatesBn> doInBackground(String... params) {
        try {
            URL url = new URL(params[0]);
            connection = (HttpURLConnection) url.openConnection();
            connection.setConnectTimeout(Utilities.getConnTimeout(MainActivity.this));
            connection.connect();
            httpStatus = connection.getResponseCode();
            in = connection.getInputStream();
            reader = new BufferedReader(new InputStreamReader(in));
            while ((line = reader.readLine()) != null) {
                buffer.append(line);
            }
            String finalJson = buffer.toString();

            JSONObject parentObject = new JSONObject(finalJson);
            JSONArray parentArray = parentObject.getJSONArray("Loans");

            ArrayList<LoanRatesBn> loanRatesBnArrayList = new ArrayList<>();

            Gson gson = new Gson();
            for (int i = 0; i < parentArray.length(); i++) {
                JSONObject finalObject = parentArray.getJSONObject(i);
                LoanRatesBn loanRatesBn = gson.fromJson(finalObject.toString(), LoanRatesBn.class);
                loanRatesBnArrayList.add(loanRatesBn);
            }
            return loanRatesBnArrayList;

        } catch (SocketTimeoutException ex) {
            Utilities.stopProgressDialog(progressDialog);
            isTimeout = true;

        } catch (Exception ex) {
            Utilities.stopProgressDialog(progressDialog);

        } finally {
            if (connection != null) {
                connection.disconnect();
            }
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }
        return null;
    }

    @Override
    protected void onPostExecute(ArrayList<LoanRatesBn> result) {
        super.onPostExecute(result);
        if (isTimeout) {
            Utilities.timeoutErrorAlert(MainActivity.this);
        } else if (Utilities.isValidResponse(httpStatus)) {
            Utilities.stopProgressDialog(progressDialog);
            Intent intent = new Intent(MainActivity.this, LoanRates.class);
            Resources res = MainActivity.this.getResources();
            intent.putExtra("pageName", res.getString(R.string.loanRatesStr));
            intent.putExtra("loanRatesBnArrayList", result);
            startActivity(intent);
        } else {
            Utilities.serverErrorAlert(MainActivity.this);
        }

    }
}

0 个答案:

没有答案