0

I have a private app for work installed on a phone running Android 8 and a tablet running Android 8.1 and it's working fine on both but when I installed it on my new phone running Android 10, it gives me an JSON error. The rest of the app works fine but it's showing a JSONObject as null. Is this just a setting or has something changed with Android 10?

@Override
        protected Void doInBackground(Void... arg0) {

            HttpJsonParser httpJsonParser = new HttpJsonParser();
            Map<String, String> httpParams = new HashMap<>();
            
            JSONObject jsonObject = httpJsonParser.makeHttpRequest(GET_VERSION_URL, "GET", httpParams);

            if (jsonObject != null) { // <- Returns fine on Android 8.1 but not Android 10

                try {
                    ...
                } catch (final JSONException e) {
                    ...
                }

            } else {
                MainActivity.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(MainActivity.this,"Error.", Toast.LENGTH_LONG).show(); // <-Goes to this everytime
                    }
                });
            }

            return null;

        }

1 Answer 1

1

I don't think your problem is with JSONObject itself. More probably is has to do with changes and restrictions with how HTTP calls are made in Android. Some changes are introduced with newer version like:

  • Requiring all request to be made using HTTPS.
  • Deprecation of old HTTP Clients like Apache's one.

Some of those restrictions can be bypassed enabling a config flag, this will give you more time to update your implementation. But the recommended approach is to follow the new guidelines as stop using deprecated stuff.

Go here, and check the "Behavior changes for all apps" and "Behavior changes for apps targeting API XX+" pages for the version of Android where your app doesn't work. That will give you a clue about if this is the problem.

Sign up to request clarification or add additional context in comments.

1 Comment

You are exactly right! Its a URL change that I quickly found here. Thank you for the info and the link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.