App中的数据加载显示没有互联网连接

时间:2018-01-31 09:50:36

标签: php android json networking

我正在开发一个Android应用程序,我需要向服务器请求数据。但是,即使我已连接到无线网络或个人网络,请求也始终返回错误“无互联网连接”。 有时数据正在增加,但在向服务器发送多个请求后,没有显示互联网连接消息。

以下是获取数据的示例代码。

public void getPostRequests(final String post_id, final String seeker_count) {
    final List<SeekerItem> seekerItems = new ArrayList<>();
    final CommonRecyclerView commonRecyclerView = new CommonRecyclerView(ViewPost.this, ll_req_view_recruiter.getRootView(), null);
    final SeekerAdapter seekerAdapter = new SeekerAdapter(ViewPost.this, coordinatorLayout_view_post, sharedPreferencesDatabase, 1, post_id, seekerItems, commonRecyclerView.getRecyclerView());
    commonRecyclerView.setAdapter(seekerAdapter);
    commonRecyclerView.getFloatingActionButton().setVisibility(View.GONE);
    commonRecyclerView.getRecyclerView().setNestedScrollingEnabled(false);

    if (!TextUtils.equals(seeker_count, "0")) {
        AndroidNetworking.post(IpConfig.URL_GET_RECRUITER_REQ)
                .addBodyParameter("post_id", post_id)
                .addBodyParameter("last_id", "0")
                .setTag("getPost")
                .setPriority(Priority.LOW)
                .build()
                .getAsJSONObject(new JSONObjectRequestListener() {
                    @Override
                    public void onResponse(JSONObject response) {
                        commonRecyclerView.getProgressBar().setVisibility(View.GONE);
                        commonRecyclerView.getTextView().setVisibility(View.GONE);
                        seekerItems.addAll(DecodeJson.getSeeker(response, commonRecyclerView.getTextView()));
                        seekerAdapter.notifyDataSetChanged();
                    }

                    @Override
                    public void onError(ANError anError) {
                        commonRecyclerView.getProgressBar().setVisibility(View.GONE);
                        commonRecyclerView.getTextView().setVisibility(View.VISIBLE);
                        if (TextUtils.equals(anError.getErrorDetail(), "connectionError")) {
                            commonRecyclerView.getTextView().setText("No Internet Connection");
                        } else {
                            commonRecyclerView.getTextView().setText(anError.getErrorDetail());
                        }
                    }
                });
    }
}

0 个答案:

没有答案