HTTP POST request ANDROID 4 (working in 2.3)?

橙三吉。 提交于 2019-12-01 00:05:53

You need to put this in an Async task, it will not run in the main thread in 3.0 >

use this:

public class PostTask extends AsyncTask<Void, String, Boolean> {

        @Override
        protected Boolean doInBackground(Void... params) {
            boolean result = false;

            //All your code goes in here 

            //If you want to do something on the UI use progress update

            publishProgress("progress");
            return result;
        }

        protected void onProgressUpdate(String... progress) {
            StringBuilder str = new StringBuilder();
                for (int i = 1; i < progress.length; i++) {
                    str.append(progress[i] + " ");
                }

        }
    }

You need a reference to it outside the async task

PostTask posttask;

then you need to start it

posttask = new PostTask();
posttask.execute();

I had the exact same problem a couple of days ago, goodluck

With Android 4.0 you cant use http connection without using a Thread (with a runnable, asyinctask ... )

The best you can do is implements a Thread but if you cant do it you cant delete in the android manifest android:targetVersion="14".

If you need some elements of the version 14/higher like Holo theme or something you can configure in

Right clink in the project --> Propierties --> Android --> Project Built Target = 14 or that you want

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!