Java onPostExecute返回失败

Java onPostExecute返回失败,java,android,web-services,android-asynctask,shared-libraries,Java,Android,Web Services,Android Asynctask,Shared Libraries,我尝试将部分源代码实现为库,但它似乎会导致一个问题,即每次运行onPostExecute时,onPostExecute都返回“failure” 我想我只需要弄清楚如何将我的onPostExecute方法连接到我的新库,但我不确定到底该怎么做 提前感谢, 阿曼尼·斯旺 图书馆: import java.io.BufferedReader; import java.io.DataInputStream; import java.io.IOException; import java.io.Input

我尝试将部分源代码实现为库,但它似乎会导致一个问题,即每次运行onPostExecute时,onPostExecute都返回“failure”

我想我只需要弄清楚如何将我的onPostExecute方法连接到我的新库,但我不确定到底该怎么做

提前感谢,

阿曼尼·斯旺

图书馆:

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.util.zip.GZIPInputStream;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLException;
import org.xml.sax.SAXException;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;

/*this class performs the call to webservice in the background*/
public class NetworkTask extends AsyncTask<String, Integer, InputStream> {
    InputStream stream = null;
    @Override
    protected void onPreExecute() {

        super.onPreExecute();
    }

    @Override
    protected InputStream doInBackground(String... params) {

        try {
            // saving the response in InputStream
            stream = getQueryResults("https://dl.dropboxusercontent.com/u/31771876/GetPhoneSettings-ST-rsp-eng.xml");
        //  stream = new BufferedInputStream(https.getInputStream());
                   DataInputStream in = new DataInputStream(stream);
                       BufferedReader br = new BufferedReader(new InputStreamReader(in));
                     String strLine; 
                       while ((strLine = br.readLine()) != null) { // Print the content on the console
                           System.out.println (strLine); 
                       System.out.println (strLine); 
                             in.close();
                       }


        } catch (IOException e) {


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


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


            e.printStackTrace();
        }
        // The code below plays a Simple Promo animation
        return stream;


        }



protected synchronized InputStream getQueryResults(String urlQueryString)
        throws IOException, SAXException, SSLException,
        SocketTimeoutException, Exception {

    HttpsURLConnection https = null;
    String uri = urlQueryString;

    URL urlo = new URL(uri);

    try {
        https = (HttpsURLConnection) urlo.openConnection();
        https.setConnectTimeout(20000); // 20 second timeout
        https.setRequestProperty("Connection", "Keep-Alive");

        if ("gzip".equals(https.getContentEncoding())) {
            stream = new GZIPInputStream(stream);
        } else
            stream = https.getInputStream();

    } catch (SSLException e) {

        e.printStackTrace();

    } catch (SocketTimeoutException e) {

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

        e.printStackTrace();

    } catch (Exception e) {

        e.printStackTrace();

    } finally {

    }

    return stream;
}





}
更新活动:

public class UpdateActivity extends Activity implements OnClickListener {
    public static ArrayList<String> NameArr = new ArrayList<String>();
    public static ArrayList<String> ValueArr = new ArrayList<String>();
    public static ArrayList<String> nameArr = new ArrayList<String>();
    public static ArrayList<String> ApnArr = new ArrayList<String>();
    public static ArrayList<String> mmscArr = new ArrayList<String>();
    public static ArrayList<String> mmsportArr = new ArrayList<String>();
    public static ArrayList<String> mmsproxyArr = new ArrayList<String>();
    public static ArrayList<String> portArr = new ArrayList<String>();
    public static ArrayList<String> proxyArr = new ArrayList<String>();
    private ImageView mProgressImageview1;
    private ImageView mProgressImageview2;
    private ImageView mProgressImageview3;
    private ImageView mProgressImageview4;
    private ImageView mProgressImageview5;
    public static int count;
    AlertDialog mErrorAlert = null;
    int version;
    public static int TotalSteps = 8;
    private TelephonyManager tm;
    private static final String LOG_TAG = "STDataSettings";
    private Button mUpdateButton = null;
    private Button mAssistUpdateButton = null;
    private Button mAssistInstrButton = null;
    private TextView mReadAgainButton = null;
    private int mInstructionNumber = 0;
    AlertDialog mConfirmAlert = null;
    public static InputStream stream = null;
    public static XmlParserHandlerFinal handler;
    private NetworkTask task;
    private AnimationDrawable loadingAnimation;
    private static final String TAG = "UpdateActivity";
    Context ctx;
    private Button assist_update_btn = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        int networkType = tm.getNetworkType();
        int phoneType = tm.getPhoneType();
        handler = new XmlParserHandlerFinal();
        int version = android.os.Build.VERSION.SDK_INT;
        if (phoneType == TelephonyManager.PHONE_TYPE_CDMA
                || (phoneType != TelephonyManager.PHONE_TYPE_GSM
                        && networkType != TelephonyManager.NETWORK_TYPE_GPRS
                        && networkType != TelephonyManager.NETWORK_TYPE_EDGE
                        && networkType != TelephonyManager.NETWORK_TYPE_HSDPA
                        && networkType != TelephonyManager.NETWORK_TYPE_HSPA
                        && networkType != TelephonyManager.NETWORK_TYPE_HSPAP
                        && networkType != TelephonyManager.NETWORK_TYPE_HSUPA
                        && networkType != TelephonyManager.NETWORK_TYPE_UMTS && networkType != TelephonyManager.NETWORK_TYPE_LTE)) {
            // If the phone type is CDMA or
            // the phone phone type is not GSM and the network type is none of
            // the network types indicated in the statement
            // Display incompatibility message
            showAlert(getString(R.string.incomp_sm_dialog));
            // Network type is looked because some tablets have no phone type.
            // We rely on network type in such cases
        } else if (tm.getSimState() == TelephonyManager.SIM_STATE_ABSENT
                || !(tm.getSimOperator()
                        .equals(getString(R.string.numeric_tmo)) || (tm
                        .getSimOperator()
                        .equals(getString(R.string.numeric_att))))) {

            // if SIM is present and is NOT a T-Mo network SIM,
            // display Error message alert indicating to use SM SIM
            showAlert(getString(R.string.insert_sm_dialog));
        }// No SIM or SIM with T-Mo MNC MCC present
        else if (version < VERSION_CODES.ICE_CREAM_SANDWICH) {
            // Initial UI setup for versions lower than ICS
            setContentView(R.layout.update);
            mUpdateButton = (Button) findViewById(R.id.update_button);

            mUpdateButton.setOnClickListener(this);

        } else {// ICS and up

            if ((tm.getSimOperator()).equals(getString(R.string.numeric_tmo))
                    || (tm.getSimOperator())
                            .equals(getString(R.string.numeric_att))) {
                task = new NetworkTask();
                task.execute("");
                // Device has T-Mo network SIM card MCC and MNC correctly
                // populated
                // Reduce number of steps to 6
                TotalSteps = 6;
            }

        }
    }

    public void onClick(View v) {
        if (v == mUpdateButton) {
            // Update button for versions lower than ICS is selected

            onClickMethod(v);

            Intent i = new Intent(this, ConfigFinalActivity.class);
            startActivity(i);
            finish();
        } else

        if (v.getId() == R.id.assist_update_btn) {

            // Update button for ICS and up is selected
            // Get the TextView in the Assist Update UI
            TextView tv = (TextView) findViewById(R.id.apn_app_text_cta2);
            String text = "";
            CharSequence styledText = text;
            switch (mInstructionNumber) {
            case 0:
                // Retrieve the instruction string resource corresponding the
                // 2nd set of instructions
                text = String.format(getString(R.string.apn_app_text_instr),
                        TotalSteps);
                styledText = Html.fromHtml(text);
                // Update the TextView with the correct set of instructions
                tv.setText(styledText);
                // Increment instruction number so the correct instructions
                // string resource can be retrieve the next time the update
                // button is pressed
                mInstructionNumber++;
                break;
            case 1:
                text = getString(R.string.apn_app_text_instr2);
                styledText = Html.fromHtml(text);
                tv.setText(styledText);
                // Increment instruction number so the correct instructions
                // string resource can be retrieve the next time the update
                // button is pressed
                mInstructionNumber++;
                break;
            case 2:
                // Final set of instructions-Change to the corresponding layout

                setContentView(R.layout.assist_instructions);
                String assistUpdateInstr = String.format(
                        getString(R.string.apn_app_text_instr3), TotalSteps);
                styledText = Html.fromHtml(assistUpdateInstr);
                TextView assistInstrText = (TextView) findViewById(R.id.updated_text);
                assistInstrText.setText(styledText);
                mAssistInstrButton = (Button) findViewById(R.id.assist_instr_btn);
                mReadAgainButton = (TextView) findViewById(R.id.read_again_btn);
                mAssistInstrButton.setOnClickListener(this);
                mReadAgainButton.setOnClickListener(this);
            }
        } else if (v == mAssistInstrButton) {
            // "LET'S DO THIS" Button in final instructions screen for ICS and
            // up is selected
            // Create ConfigActivity Intent
            Intent i = new Intent(this, ConfigFinalActivity.class);
            // Invoke ConfigActivity Intent to start the assisted update
            startActivity(i);
            startActivity(new Intent(Settings.ACTION_APN_SETTINGS));

        } else if (v == mReadAgainButton) {
            // go back to 1st set of instructions if read again is selected
            mInstructionNumber = 0;
            setContentView(R.layout.assist_update);
            String assistUpdate = getString(R.string.apn_app_text_cta2);
            CharSequence styledText = Html.fromHtml(assistUpdate);
            TextView assistText = (TextView) findViewById(R.id.apn_app_text_cta2);
            assistText.setText(styledText);
            mAssistUpdateButton = (Button) findViewById(R.id.assist_update_btn);
            mAssistUpdateButton.setOnClickListener(this);
        }
    }

    public void onClickMethod(View v) {
        mUpdateButton = (Button) findViewById(R.drawable.btn_update_active_hdpi);

    }

    private void showAlert(String message) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(message).setPositiveButton("OK",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        UpdateActivity.this.finish();
                    }
                });
        mConfirmAlert = builder.create();
        mConfirmAlert.show();
    }

    // AsyncTask to call web service
    class NetworkTask extends AsyncTask<String, Integer, InputStream> {

        @Override
        protected void onPreExecute() {

            super.onPreExecute();
        }

        @Override
        protected InputStream doInBackground(String... params) {

            try {
                // saving the response in InputStream
                stream = getQueryResults("https://dl.dropboxusercontent.com/u/31771876/GetPhoneSettings-ST-rsp-eng.xml");
                // stream = new BufferedInputStream(https.getInputStream());
                DataInputStream in = new DataInputStream(stream);
                BufferedReader br = new BufferedReader(
                        new InputStreamReader(in));
                String strLine;
                while ((strLine = br.readLine()) != null) { // Print the content
                    // on the console
                    System.out.println(strLine);
                    System.out.println(strLine);
                    in.close();
                }

            } catch (IOException e) {

                Log.v(LOG_TAG, e.toString());
                e.printStackTrace();
            } catch (SAXException e) {

                Log.v(LOG_TAG, e.toString());
                e.printStackTrace();
            } catch (Exception e) {

                Log.v(LOG_TAG, e.toString());
                e.printStackTrace();
            }
            // The code below plays a Simple Promo animation

            for (int incr = 0; incr < 2; incr++) {
                // Sleep for 1/2 second
                // Invoke UI to change updating text to show sequential dot
                // loading animation
                publishProgress(R.drawable.loading_full,
                        R.drawable.loading_empty, R.drawable.loading_empty,
                        R.drawable.loading_empty, R.drawable.loading_empty);
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    Log.d(TAG, "sleep failure");
                }
                publishProgress(R.drawable.loading_full,
                        R.drawable.loading_full, R.drawable.loading_empty,
                        R.drawable.loading_empty, R.drawable.loading_empty);
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    Log.d(TAG, "sleep failure");
                }
                publishProgress(R.drawable.loading_full,
                        R.drawable.loading_full, R.drawable.loading_full,
                        R.drawable.loading_empty, R.drawable.loading_empty);
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    Log.d(TAG, "sleep failure");
                }
                publishProgress(R.drawable.loading_full,
                        R.drawable.loading_full, R.drawable.loading_full,
                        R.drawable.loading_full, R.drawable.loading_empty);
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    Log.d(TAG, "sleep failure");
                }
                publishProgress(R.drawable.loading_full,
                        R.drawable.loading_full, R.drawable.loading_full,
                        R.drawable.loading_full, R.drawable.loading_full);

                // Sleep for 1/2 second
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    Log.d(TAG, "sleep failure");
                }
            }
            return stream;
        }

        /*
         * Sends a query to server and gets back the parsed results in a bundle
         * urlQueryString - URL for calling the webservice
         */
        protected synchronized InputStream getQueryResults(String urlQueryString)
                throws IOException, SAXException, SSLException,
                SocketTimeoutException, Exception {

            HttpsURLConnection https = null;
            String uri = urlQueryString;

            URL urlo = new URL(uri);

            try {
                https = (HttpsURLConnection) urlo.openConnection();
                https.setConnectTimeout(20000); // 20 second timeout
                https.setRequestProperty("Connection", "Keep-Alive");

                if ("gzip".equals(https.getContentEncoding())) {
                    stream = new GZIPInputStream(stream);
                } else
                    stream = https.getInputStream();

            } catch (SSLException e) {
                Log.e(LOG_TAG, e.toString());
                e.printStackTrace();

            } catch (SocketTimeoutException e) {
                Log.e(LOG_TAG, e.toString());
                e.printStackTrace();
            } catch (IOException e) {
                Log.e(LOG_TAG, e.toString());
                e.printStackTrace();

            } catch (Exception e) {
                Log.e(LOG_TAG, e.toString());
                e.printStackTrace();

            } finally {

            }

            return stream;
        }

        @Override
        protected void onProgressUpdate(Integer... progress) {

            // Call function to update image view

            setProgressImgView(progress[0], progress[1], progress[2],
                    progress[3], progress[4]);

        }

        @Override
        protected void onPostExecute(InputStream stream) {
            super.onPostExecute(stream);
            // This method is called to parse the response and save the
            // ArrayLists
            success();
            assistUpdate();

        }

    }

    private void assistUpdate() {
        // Displaying final layout after pre-ICS automatic settings update
        setContentView(R.layout.assist_update);
        assist_update_btn = (Button) findViewById(R.id.assist_update_btn);
        assist_update_btn.setOnClickListener(this);

    }

    private void setProgressImgView(Integer imageViewId1, Integer imageViewId2,
            Integer imageViewId3, Integer imageViewId4, Integer imageViewId5) {
        // update image view with the updating dots
        // Reset view layout in case orientation while updating
        setContentView(R.layout.updating);

        mProgressImageview1 = (ImageView) findViewById(R.id.loading_empty1);
        mProgressImageview1.setBackgroundResource(imageViewId1);
        mProgressImageview2 = (ImageView) findViewById(R.id.loading_empty2);
        mProgressImageview2.setBackgroundResource(imageViewId2);
        mProgressImageview3 = (ImageView) findViewById(R.id.loading_empty3);
        mProgressImageview3.setBackgroundResource(imageViewId3);
        mProgressImageview4 = (ImageView) findViewById(R.id.loading_empty4);
        mProgressImageview4.setBackgroundResource(imageViewId4);
        mProgressImageview5 = (ImageView) findViewById(R.id.loading_empty5);
        mProgressImageview5.setBackgroundResource(imageViewId5);

    }

    @Override
    protected void onRestart() {
        super.onRestart();

        if (mErrorAlert != null)
            mErrorAlert.dismiss();
    }

    private void endUpdate(View v) {
        finish();

    }

    public void success() {

        // to parse the response
        try {
            handler.getQueryResponse(stream);

        } catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        // to set method to save the ArryaLists from the parser
        setArrayList();
        Intent i = new Intent(this, ConfigFinalActivity.class);
        startActivity(i);

    }

    // method to save the ArrayLists from parser
    public static void setArrayList() {
        nameArr = handler.getnameArr();
        ApnArr = handler.getApnArr();
        mmscArr = handler.getMMSCArr();
        mmsproxyArr = handler.getMmscProxyArr();
        mmsportArr = handler.getMmsPortArr();
        proxyArr = handler.getMmscProxyArr();
        portArr = handler.getMmsPortArr();
        count = handler.getCount();
        // System.out.println("testing123");

        for (int i = 0; i < nameArr.size() - 1; i++) {
            System.out.println(nameArr.get(i));
        }

        for (int i = 0; i < ApnArr.size() - 1; i++) {
            System.out.println(ApnArr.get(i));
        }
    }
}
公共类UpdateActivity扩展了活动实现OnClickListener{
public static ArrayList NameArr=new ArrayList();
public static ArrayList ValueArr=new ArrayList();
public static ArrayList nameArr=new ArrayList();
public static ArrayList ApnArr=new ArrayList();
public static ArrayList mmscArr=new ArrayList();
public static ArrayList mmsportArr=new ArrayList();
public static ArrayList mmsproxyArr=new ArrayList();
public static ArrayList portArr=new ArrayList();
public static ArrayList proxyArr=new ArrayList();
私有图像视图mProgressImageview1;
私有图像视图mProgressImageview2;
私有图像视图mProgressImageview3;
私有图像视图mProgressImageview4;
私有图像视图mprogressimageview 5;
公共静态整数计数;
AlertDialog mErrorAlert=null;
int版本;
公共静态int TotalSteps=8;
专用电话管理器tm;
私有静态最终字符串日志\u TAG=“STDataSettings”;
私有按钮mUpdateButton=null;
private Button-DateButton=null;
私有按钮mAssistInstrButton=null;
私有文本视图mReadAgainButton=null;
私有int mInstructionNumber=0;
AlertDialog mConfirmAlert=null;
公共静态InputStream=null;
公共静态XmlParserHandlerFinal处理程序;
专用网络任务;
私有动画绘制可加载动画;
私有静态最终字符串TAG=“UpdateActivity”;
上下文ctx;
专用按钮辅助\更新\ btn=null;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
tm=(电话管理器)getSystemService(电话服务);
int networkType=tm.getNetworkType();
int phoneType=tm.getPhoneType();
handler=new XmlParserHandlerFinal();
int version=android.os.Build.version.SDK\u int;
if(phoneType==TelephonyManager.PHONE\u TYPE\u CDMA
||(phoneType!=TelephonyManager.PHONE\u TYPE\u GSM
&&networkType!=TelephonyManager.NETWORK\u TYPE\u GPRS
&&networkType!=TelephonyManager.NETWORK\u TYPE\u EDGE
&&networkType!=TelephonyManager.NETWORK\u TYPE\u HSDPA
&&networkType!=TelephonyManager.NETWORK\u TYPE\u HSPA
&&networkType!=TelephonyManager.NETWORK\u TYPE\u HSPAP
&&networkType!=TelephonyManager.NETWORK\u TYPE\u HSUPA
&&networkType!=TelephonyManager.NETWORK\u TYPE\u UMTS&&networkType!=TelephonyManager.NETWORK\u TYPE\u LTE)){
//如果电话类型为CDMA或
//电话类型不是GSM,网络类型不是
//声明中指示的网络类型
//显示不兼容消息
showAlert(getString(R.string.incomp_sm_对话框));
//查看网络类型是因为某些平板电脑没有电话类型。
//在这种情况下,我们依赖于网络类型
}else如果(tm.getSimState()==TelephonyManager.SIM_状态_不存在
||!(tm.getSimOperator()
.equals(getString(R.string.numeric_tmo))| |(tm
.getSimOperator()
.equals(getString(R.string.numeric_att‘‘‘)’){
//如果SIM卡存在且不是T-Mo网络SIM卡,
//显示错误消息警报,指示使用SM SIM卡
showAlert(getString(R.string.insert_sm_对话框));
}//没有SIM卡或存在T-Mo跨国公司MCC的SIM卡
否则如果(版本<版本代码.冰淇淋\u三明治){
//低于ICS版本的初始UI设置
setContentView(R.layout.update);
mUpdateButton=(按钮)findViewById(R.id.update_按钮);
mUpdateButton.setOnClickListener(此);
}else{//ICS及以上
if((tm.getSimOperator()).equals(getString(R.string.numeric_tmo))
||(tm.getSimOperator())
.equals(getString(R.string.numeric_att))){
任务=新的网络任务();
任务。执行(“”);
//设备正确安装了T-Mo网络SIM卡MCC和MNC
//人口
//将步骤数减少到6个
总步数=6;
}
}
}
公共void onClick(视图v){
if(v==mUpdateButton){
//选择低于ICS版本的更新按钮
方法(五);
意向i=新意向(此,configfinalivity.class);
星触觉(i);
完成();
}否则
如果(v.getId()==R.id.assist\u update\u btn){
//已选择ICS和up的更新按钮
//在辅助更新UI中获取文本视图
TextView tv=(TextView)findViewById(R.id.apn\u app\u text\u cta2);
字符串文本=”;
CharSequence styledText=文本;
开关(最小结构编号){
案例0:
//检索对应的指令字符串资源
//第二套说明
text=String.format(getString(R.String.apn\u app\u text\u instr),
总步骤);
styledText=Html.fromHtml(文本);
//使用正确的指令集更新TextView
tv.setText(styledText);
//增加指令编号,以便正确安装
public class UpdateActivity extends Activity implements OnClickListener {
    public static ArrayList<String> NameArr = new ArrayList<String>();
    public static ArrayList<String> ValueArr = new ArrayList<String>();
    public static ArrayList<String> nameArr = new ArrayList<String>();
    public static ArrayList<String> ApnArr = new ArrayList<String>();
    public static ArrayList<String> mmscArr = new ArrayList<String>();
    public static ArrayList<String> mmsportArr = new ArrayList<String>();
    public static ArrayList<String> mmsproxyArr = new ArrayList<String>();
    public static ArrayList<String> portArr = new ArrayList<String>();
    public static ArrayList<String> proxyArr = new ArrayList<String>();
    private ImageView mProgressImageview1;
    private ImageView mProgressImageview2;
    private ImageView mProgressImageview3;
    private ImageView mProgressImageview4;
    private ImageView mProgressImageview5;
    public static int count;
    AlertDialog mErrorAlert = null;
    int version;
    public static int TotalSteps = 8;
    private TelephonyManager tm;
    private static final String LOG_TAG = "STDataSettings";
    private Button mUpdateButton = null;
    private Button mAssistUpdateButton = null;
    private Button mAssistInstrButton = null;
    private TextView mReadAgainButton = null;
    private int mInstructionNumber = 0;
    AlertDialog mConfirmAlert = null;
    public static InputStream stream = null;
    public static XmlParserHandlerFinal handler;
    private NetworkTask task;
    private AnimationDrawable loadingAnimation;
    private static final String TAG = "UpdateActivity";
    Context ctx;
    private Button assist_update_btn = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        int networkType = tm.getNetworkType();
        int phoneType = tm.getPhoneType();
        handler = new XmlParserHandlerFinal();
        int version = android.os.Build.VERSION.SDK_INT;
        if (phoneType == TelephonyManager.PHONE_TYPE_CDMA
                || (phoneType != TelephonyManager.PHONE_TYPE_GSM
                        && networkType != TelephonyManager.NETWORK_TYPE_GPRS
                        && networkType != TelephonyManager.NETWORK_TYPE_EDGE
                        && networkType != TelephonyManager.NETWORK_TYPE_HSDPA
                        && networkType != TelephonyManager.NETWORK_TYPE_HSPA
                        && networkType != TelephonyManager.NETWORK_TYPE_HSPAP
                        && networkType != TelephonyManager.NETWORK_TYPE_HSUPA
                        && networkType != TelephonyManager.NETWORK_TYPE_UMTS && networkType != TelephonyManager.NETWORK_TYPE_LTE)) {
            // If the phone type is CDMA or
            // the phone phone type is not GSM and the network type is none of
            // the network types indicated in the statement
            // Display incompatibility message
            showAlert(getString(R.string.incomp_sm_dialog));
            // Network type is looked because some tablets have no phone type.
            // We rely on network type in such cases
        } else if (tm.getSimState() == TelephonyManager.SIM_STATE_ABSENT
                || !(tm.getSimOperator()
                        .equals(getString(R.string.numeric_tmo)) || (tm
                        .getSimOperator()
                        .equals(getString(R.string.numeric_att))))) {

            // if SIM is present and is NOT a T-Mo network SIM,
            // display Error message alert indicating to use SM SIM
            showAlert(getString(R.string.insert_sm_dialog));
        }// No SIM or SIM with T-Mo MNC MCC present
        else if (version < VERSION_CODES.ICE_CREAM_SANDWICH) {
            // Initial UI setup for versions lower than ICS
            setContentView(R.layout.update);
            mUpdateButton = (Button) findViewById(R.id.update_button);

            mUpdateButton.setOnClickListener(this);

        } else {// ICS and up

            if ((tm.getSimOperator()).equals(getString(R.string.numeric_tmo))
                    || (tm.getSimOperator())
                            .equals(getString(R.string.numeric_att))) {
                task = new NetworkTask();
                task.execute("");
                // Device has T-Mo network SIM card MCC and MNC correctly
                // populated
                // Reduce number of steps to 6
                TotalSteps = 6;
            }

        }
    }

    public void onClick(View v) {
        if (v == mUpdateButton) {
            // Update button for versions lower than ICS is selected

            onClickMethod(v);

            Intent i = new Intent(this, ConfigFinalActivity.class);
            startActivity(i);
            finish();
        } else

        if (v.getId() == R.id.assist_update_btn) {

            // Update button for ICS and up is selected
            // Get the TextView in the Assist Update UI
            TextView tv = (TextView) findViewById(R.id.apn_app_text_cta2);
            String text = "";
            CharSequence styledText = text;
            switch (mInstructionNumber) {
            case 0:
                // Retrieve the instruction string resource corresponding the
                // 2nd set of instructions
                text = String.format(getString(R.string.apn_app_text_instr),
                        TotalSteps);
                styledText = Html.fromHtml(text);
                // Update the TextView with the correct set of instructions
                tv.setText(styledText);
                // Increment instruction number so the correct instructions
                // string resource can be retrieve the next time the update
                // button is pressed
                mInstructionNumber++;
                break;
            case 1:
                text = getString(R.string.apn_app_text_instr2);
                styledText = Html.fromHtml(text);
                tv.setText(styledText);
                // Increment instruction number so the correct instructions
                // string resource can be retrieve the next time the update
                // button is pressed
                mInstructionNumber++;
                break;
            case 2:
                // Final set of instructions-Change to the corresponding layout

                setContentView(R.layout.assist_instructions);
                String assistUpdateInstr = String.format(
                        getString(R.string.apn_app_text_instr3), TotalSteps);
                styledText = Html.fromHtml(assistUpdateInstr);
                TextView assistInstrText = (TextView) findViewById(R.id.updated_text);
                assistInstrText.setText(styledText);
                mAssistInstrButton = (Button) findViewById(R.id.assist_instr_btn);
                mReadAgainButton = (TextView) findViewById(R.id.read_again_btn);
                mAssistInstrButton.setOnClickListener(this);
                mReadAgainButton.setOnClickListener(this);
            }
        } else if (v == mAssistInstrButton) {
            // "LET'S DO THIS" Button in final instructions screen for ICS and
            // up is selected
            // Create ConfigActivity Intent
            Intent i = new Intent(this, ConfigFinalActivity.class);
            // Invoke ConfigActivity Intent to start the assisted update
            startActivity(i);
            startActivity(new Intent(Settings.ACTION_APN_SETTINGS));

        } else if (v == mReadAgainButton) {
            // go back to 1st set of instructions if read again is selected
            mInstructionNumber = 0;
            setContentView(R.layout.assist_update);
            String assistUpdate = getString(R.string.apn_app_text_cta2);
            CharSequence styledText = Html.fromHtml(assistUpdate);
            TextView assistText = (TextView) findViewById(R.id.apn_app_text_cta2);
            assistText.setText(styledText);
            mAssistUpdateButton = (Button) findViewById(R.id.assist_update_btn);
            mAssistUpdateButton.setOnClickListener(this);
        }
    }

    public void onClickMethod(View v) {
        mUpdateButton = (Button) findViewById(R.drawable.btn_update_active_hdpi);

    }

    private void showAlert(String message) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(message).setPositiveButton("OK",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        UpdateActivity.this.finish();
                    }
                });
        mConfirmAlert = builder.create();
        mConfirmAlert.show();
    }

    // AsyncTask to call web service
    class NetworkTask extends AsyncTask<String, Integer, InputStream> {

        @Override
        protected void onPreExecute() {

            super.onPreExecute();
        }

        @Override
        protected InputStream doInBackground(String... params) {

            try {
                // saving the response in InputStream
                stream = getQueryResults("https://dl.dropboxusercontent.com/u/31771876/GetPhoneSettings-ST-rsp-eng.xml");
                // stream = new BufferedInputStream(https.getInputStream());
                DataInputStream in = new DataInputStream(stream);
                BufferedReader br = new BufferedReader(
                        new InputStreamReader(in));
                String strLine;
                while ((strLine = br.readLine()) != null) { // Print the content
                    // on the console
                    System.out.println(strLine);
                    System.out.println(strLine);
                    in.close();
                }

            } catch (IOException e) {

                Log.v(LOG_TAG, e.toString());
                e.printStackTrace();
            } catch (SAXException e) {

                Log.v(LOG_TAG, e.toString());
                e.printStackTrace();
            } catch (Exception e) {

                Log.v(LOG_TAG, e.toString());
                e.printStackTrace();
            }
            // The code below plays a Simple Promo animation

            for (int incr = 0; incr < 2; incr++) {
                // Sleep for 1/2 second
                // Invoke UI to change updating text to show sequential dot
                // loading animation
                publishProgress(R.drawable.loading_full,
                        R.drawable.loading_empty, R.drawable.loading_empty,
                        R.drawable.loading_empty, R.drawable.loading_empty);
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    Log.d(TAG, "sleep failure");
                }
                publishProgress(R.drawable.loading_full,
                        R.drawable.loading_full, R.drawable.loading_empty,
                        R.drawable.loading_empty, R.drawable.loading_empty);
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    Log.d(TAG, "sleep failure");
                }
                publishProgress(R.drawable.loading_full,
                        R.drawable.loading_full, R.drawable.loading_full,
                        R.drawable.loading_empty, R.drawable.loading_empty);
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    Log.d(TAG, "sleep failure");
                }
                publishProgress(R.drawable.loading_full,
                        R.drawable.loading_full, R.drawable.loading_full,
                        R.drawable.loading_full, R.drawable.loading_empty);
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    Log.d(TAG, "sleep failure");
                }
                publishProgress(R.drawable.loading_full,
                        R.drawable.loading_full, R.drawable.loading_full,
                        R.drawable.loading_full, R.drawable.loading_full);

                // Sleep for 1/2 second
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    Log.d(TAG, "sleep failure");
                }
            }
            return stream;
        }

        /*
         * Sends a query to server and gets back the parsed results in a bundle
         * urlQueryString - URL for calling the webservice
         */
        protected synchronized InputStream getQueryResults(String urlQueryString)
                throws IOException, SAXException, SSLException,
                SocketTimeoutException, Exception {

            HttpsURLConnection https = null;
            String uri = urlQueryString;

            URL urlo = new URL(uri);

            try {
                https = (HttpsURLConnection) urlo.openConnection();
                https.setConnectTimeout(20000); // 20 second timeout
                https.setRequestProperty("Connection", "Keep-Alive");

                if ("gzip".equals(https.getContentEncoding())) {
                    stream = new GZIPInputStream(stream);
                } else
                    stream = https.getInputStream();

            } catch (SSLException e) {
                Log.e(LOG_TAG, e.toString());
                e.printStackTrace();

            } catch (SocketTimeoutException e) {
                Log.e(LOG_TAG, e.toString());
                e.printStackTrace();
            } catch (IOException e) {
                Log.e(LOG_TAG, e.toString());
                e.printStackTrace();

            } catch (Exception e) {
                Log.e(LOG_TAG, e.toString());
                e.printStackTrace();

            } finally {

            }

            return stream;
        }

        @Override
        protected void onProgressUpdate(Integer... progress) {

            // Call function to update image view

            setProgressImgView(progress[0], progress[1], progress[2],
                    progress[3], progress[4]);

        }

        @Override
        protected void onPostExecute(InputStream stream) {
            super.onPostExecute(stream);
            // This method is called to parse the response and save the
            // ArrayLists
            success();
            assistUpdate();

        }

    }

    private void assistUpdate() {
        // Displaying final layout after pre-ICS automatic settings update
        setContentView(R.layout.assist_update);
        assist_update_btn = (Button) findViewById(R.id.assist_update_btn);
        assist_update_btn.setOnClickListener(this);

    }

    private void setProgressImgView(Integer imageViewId1, Integer imageViewId2,
            Integer imageViewId3, Integer imageViewId4, Integer imageViewId5) {
        // update image view with the updating dots
        // Reset view layout in case orientation while updating
        setContentView(R.layout.updating);

        mProgressImageview1 = (ImageView) findViewById(R.id.loading_empty1);
        mProgressImageview1.setBackgroundResource(imageViewId1);
        mProgressImageview2 = (ImageView) findViewById(R.id.loading_empty2);
        mProgressImageview2.setBackgroundResource(imageViewId2);
        mProgressImageview3 = (ImageView) findViewById(R.id.loading_empty3);
        mProgressImageview3.setBackgroundResource(imageViewId3);
        mProgressImageview4 = (ImageView) findViewById(R.id.loading_empty4);
        mProgressImageview4.setBackgroundResource(imageViewId4);
        mProgressImageview5 = (ImageView) findViewById(R.id.loading_empty5);
        mProgressImageview5.setBackgroundResource(imageViewId5);

    }

    @Override
    protected void onRestart() {
        super.onRestart();

        if (mErrorAlert != null)
            mErrorAlert.dismiss();
    }

    private void endUpdate(View v) {
        finish();

    }

    public void success() {

        // to parse the response
        try {
            handler.getQueryResponse(stream);

        } catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        // to set method to save the ArryaLists from the parser
        setArrayList();
        Intent i = new Intent(this, ConfigFinalActivity.class);
        startActivity(i);

    }

    // method to save the ArrayLists from parser
    public static void setArrayList() {
        nameArr = handler.getnameArr();
        ApnArr = handler.getApnArr();
        mmscArr = handler.getMMSCArr();
        mmsproxyArr = handler.getMmscProxyArr();
        mmsportArr = handler.getMmsPortArr();
        proxyArr = handler.getMmscProxyArr();
        portArr = handler.getMmsPortArr();
        count = handler.getCount();
        // System.out.println("testing123");

        for (int i = 0; i < nameArr.size() - 1; i++) {
            System.out.println(nameArr.get(i));
        }

        for (int i = 0; i < ApnArr.size() - 1; i++) {
            System.out.println(ApnArr.get(i));
        }
    }
}
public class NetworkTask extends AsyncTask<String, Integer, InputStream> {

 @Override
    protected InputStream doInBackground(String... params) {
      ....
      ....
    }
}
public class UpdateActivity extends Activity implements OnClickListener {
 @Override
    protected void onCreate(Bundle savedInstanceState) {
      ....
      new NetworkTask(){
        @Override
        protected void onPreExecute() {

          super.onPreExecute();
        }
        @Override
        protected void onPostExecute(String result) {
           ....
           ....
        }
    }.execute("");
 }
}