Example usage for org.json JSONException printStackTrace

List of usage examples for org.json JSONException printStackTrace

Introduction

In this page you can find the example usage for org.json JSONException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:edu.jhu.cvrg.timeseriesstore.opentsdb.TimeSeriesUtility.java

protected static JSONObject makeResponseJSONObject(String data) {

    JSONArray product = null;//w w w .j a v a  2s .  c  o m
    JSONObject ret = null;
    try {
        product = new JSONArray(data);
        ret = (JSONObject) product.get(0);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return ret;
}

From source file:fr.bmartel.android.tictactoe.GameSingleton.java

public void changeUserName(final String username) {

    Log.i(TAG, "setting username : " + RequestBuilder.buildSetUsernameRequest(DEVICE_ID, username));

    deviceName = username;//from ww w. java 2 s . c om

    JSONObject req = new JSONObject();
    try {
        req.put(RequestConstants.DEVICE_ID, DEVICE_ID);
        req.put(RequestConstants.DEVICE_NAME, username);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    JsonObjectRequest jsObjRequest = new JsonObjectRequest(BuildConfig.APP_ROUTE + "/username", req,
            new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {

                    Log.i(TAG, "response received username : " + response.toString());

                    SharedPreferences sharedPreferences = PreferenceManager
                            .getDefaultSharedPreferences(context.getApplicationContext());
                    SharedPreferences.Editor editor = sharedPreferences.edit();
                    editor.putString(RequestConstants.DEVICE_NAME, deviceName);
                    editor.commit();

                    //broadcast username change
                    try {

                        JSONObject object = new JSONObject();
                        object.put(RequestConstants.DEVICE_NAME, deviceName);

                        ArrayList<String> eventItem = new ArrayList<>();
                        eventItem.add(object.toString());

                        broadcastUpdateStringList(BroadcastFilters.EVENT_USERNAME, eventItem);

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

                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    // TODO Auto-generated method stub
                    error.printStackTrace();
                }
            });

    jsObjRequest.setShouldCache(false);
    queue.add(jsObjRequest);
}

From source file:com.ibm.mobilefirst.mobileedge.abstractmodel.HumidityData.java

@Override
public JSONObject asJSON() {
    JSONObject json = super.asJSON();

    try {//from  ww w .  ja  v a2 s  .  c  om
        JSONObject data = new JSONObject();
        data.put("humidity", humidity);
        json.put("humidity", data);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return json;
}

From source file:uk.co.senab.photup.LoginActivity.java

private void saveFacebookSession() {
    AsyncFacebookRunner fbRunner = new AsyncFacebookRunner(mFacebook);
    fbRunner.request("me", new RequestListener() {

        public void onComplete(String response, Object state) {
            try {
                JSONObject object = new JSONObject(response);
                String id = object.getString("id");
                String name = object.getString("name");

                Session session = new Session(mFacebook, id, name);
                session.save(getApplicationContext());

                setResult(RESULT_OK);//from w w  w  .j  ava 2s.co  m
                finish();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        public void onFacebookError(FacebookError e, Object state) {
            e.printStackTrace();
        }

        public void onFileNotFoundException(FileNotFoundException e, Object state) {
            e.printStackTrace();
        }

        public void onIOException(IOException e, Object state) {
            e.printStackTrace();
        }

        public void onMalformedURLException(MalformedURLException e, Object state) {
            e.printStackTrace();
        }
    });
}

From source file:com.felkertech.n.cumulustv.activities.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Log.d(TAG, "onCreate");
    sm = new DriveSettingsManager(this);
    ActivityUtils.openIntroIfNeeded(this);
    final ChannelDatabase channelDatabase = ChannelDatabase.getInstance(MainActivity.this);
    Fabric.with(this, new Crashlytics());
    if (AppUtils.isTV(this)) {
        // Go to tv activity
        Intent leanbackIntent = new Intent(this, LeanbackActivity.class);
        leanbackIntent.setFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME);
        startActivity(leanbackIntent);/*from   w  ww  .j  a  va 2s. com*/
    }

    findViewById(R.id.add).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ActivityUtils.openPluginPicker(true, MainActivity.this);
        }
    });
    findViewById(R.id.view).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String[] channelnames = channelDatabase.getChannelNames();
            if (channelnames.length == 0) {
                new MaterialDialog.Builder(MainActivity.this).title(R.string.no_channels)
                        .content(R.string.no_channels_find).positiveText(R.string.ok).negativeText(R.string.no)
                        .callback(new MaterialDialog.ButtonCallback() {
                            @Override
                            public void onPositive(MaterialDialog dialog) {
                                super.onPositive(dialog);
                                dialog.cancel();
                                findViewById(R.id.suggested).performClick();
                            }
                        }).show();
            } else {
                try {
                    displayChannelPicker(channelDatabase.getJsonChannels(), channelnames);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    });
    findViewById(R.id.view_genres).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Generate genres
            Set<String> genreSet = new HashSet<>();
            try {
                for (JsonChannel jsonChannel : channelDatabase.getJsonChannels()) {
                    Collections.addAll(genreSet, jsonChannel.getGenres());
                }
                final String[] genreArray = genreSet.toArray(new String[genreSet.size()]);
                new MaterialDialog.Builder(MainActivity.this).title(R.string.select_genres).items(genreArray)
                        .itemsCallback(new MaterialDialog.ListCallback() {
                            @Override
                            public void onSelection(MaterialDialog dialog, View itemView, int position,
                                    CharSequence text) {
                                // Now only get certain channels
                                String selectedGenre = genreArray[position];
                                List<JsonChannel> jsonChannelList = new ArrayList<>();
                                List<String> channelNames = new ArrayList<>();
                                try {
                                    for (JsonChannel jsonChannel : channelDatabase.getJsonChannels()) {
                                        if (jsonChannel.getGenresString().contains(selectedGenre)) {
                                            jsonChannelList.add(jsonChannel);
                                            channelNames
                                                    .add(jsonChannel.getNumber() + " " + jsonChannel.getName());
                                        }
                                    }
                                    displayChannelPicker(jsonChannelList,
                                            channelNames.toArray(new String[channelNames.size()]),
                                            selectedGenre);
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        }).show();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
    findViewById(R.id.suggested).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ActivityUtils.openSuggestedChannels(MainActivity.this, gapi);
        }
    });
    findViewById(R.id.gdrive).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            gapi = ActivityUtils.GoogleDrive.connect(MainActivity.this);
        }
    });
    findViewById(R.id.more_actions).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            moreClick();
        }
    });
}

From source file:com.freecast.LudoCast.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.new_main);

    Log.d(TAG, "onCreate");

    ActionBar actionBar = getSupportActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(android.R.color.transparent));

    mAppConnected = false;//from w w  w  .  j a  v a 2s.c o m

    Vibratorstatus = true;

    ishost = false;

    updatestatus = false;

    connectstatus = false;

    editText = (EditText) findViewById(R.id.editText1);
    Blankview = (View) findViewById(R.id.BlankView);

    editText.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            editText.setCursorVisible(true);

        }
    });

    editText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence text, int start, int before, int count) {

            writeFileData(fileName, editText.getText().toString());

        }

        @Override
        public void beforeTextChanged(CharSequence text, int start, int count, int after) {

        }

        @Override
        public void afterTextChanged(Editable edit) {
            writeFileData(fileName, editText.getText().toString());
        }
    });

    readFileData(fileName);

    mCastManager = CastApplication.getCastManager(this);

    mAppConnected = mCastManager.isConnected();

    Log.d(TAG, "onCreate mAppConnected = " + mAppConnected);

    setupCastListener();

    protocol = new LudoProtocol();

    getOverflowMenu();

    Createbnt = (Button) findViewById(R.id.Startgame);
    Createbnt.setEnabled(false);
    Createbnt.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            username = editText.getText().toString();

            Log.d(TAG, "username =  " + username);

            if (username.equals("")) {

                Toast.makeText(MainActivity.this, "Please enter your name first !!!", Toast.LENGTH_SHORT)
                        .show();
                return;
            } else {

                writeFileData(fileName, username);

            }

            if (mAppConnected) {
                try {
                    String msg = protocol.genMessage_connect(username);
                    Log.d(TAG, "connect message: " + msg);
                    sendMessage(msg);

                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            } else {

                Toast.makeText(MainActivity.this, "Connect not ready, fail to start game", Toast.LENGTH_SHORT)
                        .show();

            }

        }
    });

    Button Gamerule = (Button) findViewById(R.id.GameRule);
    Gamerule.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.d(TAG, "Start Game Rule");

            Intent it = new Intent(MainActivity.this, GameRule.class);
            startActivityForResult(it, FIRST_REQUEST_CODE);

            overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);

        }
    });

    Button Gamehelp = (Button) findViewById(R.id.GameHelp);
    Gamehelp.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.d(TAG, "Start Game Help");

            Intent it = new Intent(MainActivity.this, MyGuideViewActivity.class);
            startActivityForResult(it, FIRST_REQUEST_CODE);

            overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);

        }
    });

    Createbnt.setText("Disconnected");

}

From source file:com.freecast.LudoCast.MainActivity.java

private void setupCastListener() {

    mCastConsumer = new VideoCastConsumerImpl() {

        @Override/* w w  w.  j a v a  2 s.c o  m*/
        public void onApplicationConnected(ApplicationMetadata appMetadata, String sessionId,
                boolean wasLaunched) {

            System.out.println("onApplicationConnected message = " + sessionId);

            Toast.makeText(MainActivity.this, "Device is Ready to Start Game!!!", Toast.LENGTH_SHORT).show();

            mAppConnected = true;
            try {
                Thread.currentThread().sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (mAppConnected) {
                Createbnt.setEnabled(true);
                Createbnt.setText("Start Game");
            } else {
                Createbnt.setEnabled(false);
                Createbnt.setText("Disconnected");
            }

        }

        @Override
        public void onConnected() {

            System.out.println("MainActivity onConnected ");
            Createbnt.setText("Connecting");

        }

        @Override
        public void onDisconnected() {

            System.out.println("onDisconnected message ");

            mAppConnected = false;

            if (mAppConnected) {
                Createbnt.setEnabled(true);
                Createbnt.setText("Start Game");
            } else {
                Createbnt.setEnabled(false);
                Createbnt.setText("Disconnected");
            }

        }

        @Override
        public void onFailed(int resourceId, int statusCode) {

            System.out.println("onFailed message = " + statusCode);

            mAppConnected = false;

            if (mAppConnected) {
                Createbnt.setEnabled(true);
                Createbnt.setText("Start Game");
            } else {
                Createbnt.setEnabled(false);
                Createbnt.setText("Disconnected");
            }

        }

        @Override
        public void onApplicationDisconnected(int errorCode) {

            System.out.println("onApplicationDisconnected message = " + errorCode);

            mAppConnected = false;

            if (mAppConnected) {
                Createbnt.setEnabled(true);
                Createbnt.setText("Start Game");
            } else {
                Createbnt.setEnabled(false);
                Createbnt.setText("Disconnected");
            }

        }

        @Override
        public boolean onApplicationConnectionFailed(int errorCode) {

            System.out.println("onApplicationConnectionFailed message = " + errorCode);

            mAppConnected = false;

            if (mAppConnected) {
                Createbnt.setEnabled(true);
                Createbnt.setText("Start Game");
            } else {
                Createbnt.setEnabled(false);
                Createbnt.setText("Disconnected");
            }

            return true;
        }

        @Override
        public void onDataMessageReceived(String message) {

            JSONObject obj = null;
            try {
                obj = new JSONObject(message);
            } catch (JSONException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            String command = null;
            try {
                command = obj.getString("command");
            } catch (JSONException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            if (command.equals("connect_reply")) {
                boolean ret = false;
                try {
                    ret = obj.getBoolean("ret");
                } catch (JSONException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                if (ret == false) {
                    String reason = null;
                    try {
                        reason = obj.getString("error");
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    Log.d(TAG, "error info: " + reason);
                    Toast.makeText(MainActivity.this, "Fail to connect Ludo Server !!!!", Toast.LENGTH_SHORT)
                            .show();

                } else {
                    connectstatus = true;
                    CreateConfigGame(message);
                }

            }

            try {
                protocol.parseMessage(message);
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            System.out.println("MainActivity receiver message = " + message);
        }

        @Override
        public void onConnectionSuspended(int cause) {
            Log.d(TAG, "onConnectionSuspended() was called with cause: " + cause);
            com.freecast.LudoCast.Utils.showToast(MainActivity.this, R.string.connection_temp_lost);
        }

        @Override
        public void onConnectivityRecovered() {
            com.freecast.LudoCast.Utils.showToast(MainActivity.this, R.string.connection_recovered);
        }

        @Override
        public void onCastDeviceDetected(final RouteInfo info) {
            if (!CastPreference.isFtuShown(MainActivity.this)) {
                CastPreference.setFtuShown(MainActivity.this);

                Log.d(TAG, "Route is visible: " + info);
                new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        if (mediaRouteMenuItem.isVisible()) {
                            Log.d(TAG, "Cast Icon is visible: " + info.getName());
                        }
                    }
                }, 1000);
            }
        }
    };

}

From source file:com.downloadfacebook.AsyncRequestListener.java

public void onComplete(String response, final Object state) {
    try {/*from  w  w  w  . j  a  v  a 2  s .  co  m*/
        JSONObject obj = Util.parseJson(response);
        onComplete(obj, state);
    } catch (JSONException e) {
        e.printStackTrace();
        Log.e("facebook-stream", "JSON Error:" + e.getMessage());
    } catch (FacebookError e) {
        Log.e("facebook-stream", "Facebook Error:" + e.getMessage());
    }

}

From source file:com.nextgis.firereporter.SettingsSupport.java

public SettingsSupport(Context context, PreferenceScreen screen) {
    this.screen = screen;
    this.context = context;

    // Load the preferences from an XML resource
    //addPreferencesFromResource(R.xml.preferences);

    mSendDataIntervalPref = (ListPreference) screen.findPreference(SettingsActivity.KEY_PREF_INTERVAL);
    if (mSendDataIntervalPref != null) {
        int index = mSendDataIntervalPref.findIndexOfValue(mSendDataIntervalPref.getValue());
        if (index >= 0) {
            mSendDataIntervalPref.setSummary(mSendDataIntervalPref.getEntries()[index]);
        } else {/*from ww w  .  j  a va 2 s  .com*/
            mSendDataIntervalPref.setSummary((String) mSendDataIntervalPref.getValue());
        }
    }

    mSaveBattPref = (CheckBoxPreference) screen.findPreference(SettingsActivity.KEY_PREF_SERVICE_BATT_SAVE);
    if (mSaveBattPref != null)
        mSaveBattPref.setSummary(mSaveBattPref.isChecked() ? R.string.stOn : R.string.stOff);

    mNotifyLEDPref = (CheckBoxPreference) screen.findPreference(SettingsActivity.KEY_PREF_NOTIFY_LED);
    if (mNotifyLEDPref != null)
        mNotifyLEDPref.setSummary(mNotifyLEDPref.isChecked() ? R.string.stOn : R.string.stOff);

    mPlaySoundPref = (CheckBoxPreference) screen.findPreference(SettingsActivity.KEY_PREF_NOTIFY_SOUND);
    if (mPlaySoundPref != null)
        mPlaySoundPref.setSummary(mPlaySoundPref.isChecked() ? R.string.stOn : R.string.stOff);

    mVibroPref = (CheckBoxPreference) screen.findPreference(SettingsActivity.KEY_PREF_NOTIFY_VIBRO);
    if (mVibroPref != null)
        mVibroPref.setSummary(mVibroPref.isChecked() ? R.string.stOn : R.string.stOff);

    mRowCountPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_ROW_COUNT);
    if (mRowCountPref != null)
        mRowCountPref.setSummary((String) mRowCountPref.getText());

    mFireSearchRadiusPref = (EditTextPreference) screen
            .findPreference(SettingsActivity.KEY_PREF_FIRE_SEARCH_RADIUS);
    if (mFireSearchRadiusPref != null)
        mFireSearchRadiusPref
                .setSummary((String) mFireSearchRadiusPref.getText() + " " + context.getString(R.string.km));

    mDayIntervalPref = (ListPreference) screen.findPreference(SettingsActivity.KEY_PREF_SEARCH_DAY_INTERVAL);
    if (mDayIntervalPref != null) {
        int index = mDayIntervalPref.findIndexOfValue(mDayIntervalPref.getValue());
        if (index >= 0) {
            mDayIntervalPref.setSummary(mDayIntervalPref.getEntries()[index]);
        } else {
            mDayIntervalPref.setSummary((String) mDayIntervalPref.getValue());
        }
    }

    mSearchCurrentDatePref = (CheckBoxPreference) screen
            .findPreference(SettingsActivity.KEY_PREF_SEARCH_CURR_DAY);
    if (mSearchCurrentDatePref != null)
        mSearchCurrentDatePref.setSummary(mSearchCurrentDatePref.isChecked() ? R.string.stSearchCurrentDayOn
                : R.string.stSearchCurrentDayOff);

    mNasaServerPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_NASA);
    if (mNasaServerPref != null)
        mNasaServerPref.setSummary((String) mNasaServerPref.getText());
    mNasaServerUserPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_NASA_USER);
    if (mNasaServerUserPref != null)
        mNasaServerUserPref.setSummary((String) mNasaServerUserPref.getText());

    mUserServerPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_USER);
    if (mUserServerPref != null)
        mUserServerPref.setSummary((String) mUserServerPref.getText());
    mUserServerUserPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_USER_USER);
    if (mUserServerUserPref != null)
        mUserServerUserPref.setSummary((String) mUserServerUserPref.getText());

    mScanServerUserPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_SCAN_USER);
    if (mScanServerUserPref != null)
        mScanServerUserPref.setSummary((String) mScanServerUserPref.getText());

    mNasaServerPassPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_NASA_PASS);
    mUserServerPassPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_USER_PASS);
    mScanServerPassPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_SCAN_PASS);

    final Preference checkNasaConnPref = (Preference) screen
            .findPreference(SettingsActivity.KEY_PREF_SRV_NASA_CHECK_CONN);
    final Preference checkUserConnPref = (Preference) screen
            .findPreference(SettingsActivity.KEY_PREF_SRV_USER_CHECK_CONN);
    final Preference checkScanConnPref = (Preference) screen
            .findPreference(SettingsActivity.KEY_PREF_SRV_SCAN_CHECK_CONN);

    mReturnHandler = new Handler() {
        @SuppressLint("NewApi")
        public void handleMessage(Message msg) {
            Bundle resultData = msg.getData();

            boolean bHaveErr = resultData.getBoolean(GetFiresService.ERROR);
            int nType = resultData.getInt(GetFiresService.SOURCE);
            if (bHaveErr) {
                Toast.makeText(SettingsSupport.this.context, resultData.getString(GetFiresService.ERR_MSG),
                        Toast.LENGTH_LONG).show();
                if (nType == 1) {//user
                    checkUserConnPref.setSummary(R.string.stConnectionFailed);
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                        checkUserConnPref.setIcon(R.drawable.ic_alerts_and_states_error);
                } else if (nType == 2) {//nasa
                    checkNasaConnPref.setSummary(R.string.stConnectionFailed);
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                        checkNasaConnPref.setIcon(R.drawable.ic_alerts_and_states_error);
                } else if (nType == 3) {//scanex
                    checkScanConnPref.setSummary(R.string.stConnectionFailed);
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                        checkScanConnPref.setIcon(R.drawable.ic_alerts_and_states_error);
                }
            } else {

                String sData = resultData.getString(GetFiresService.JSON);
                if (nType == 1) {//user
                    JSONObject jsonMainObject;
                    try {
                        jsonMainObject = new JSONObject(sData);
                        if (jsonMainObject.getBoolean("error")) {
                            String sMsg = jsonMainObject.getString("msg");
                            Toast.makeText(SettingsSupport.this.context, sMsg, Toast.LENGTH_LONG).show();
                            checkUserConnPref.setSummary(R.string.stConnectionFailed);
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                                checkUserConnPref.setIcon(R.drawable.ic_alerts_and_states_error);
                        } else {
                            checkUserConnPref.setSummary(R.string.stConnectionSucceeded);
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                                checkUserConnPref.setIcon(R.drawable.ic_navigation_accept);
                        }
                    } catch (JSONException e) {
                        Toast.makeText(SettingsSupport.this.context, e.toString(), Toast.LENGTH_LONG).show();
                        e.printStackTrace();
                        checkUserConnPref.setSummary(R.string.sCheckDBConnSummary);
                    }
                } else if (nType == 2) {//nasa
                    JSONObject jsonMainObject;
                    try {
                        jsonMainObject = new JSONObject(sData);
                        if (jsonMainObject.getBoolean("error")) {
                            String sMsg = jsonMainObject.getString("msg");
                            Toast.makeText(SettingsSupport.this.context, sMsg, Toast.LENGTH_LONG).show();
                            checkNasaConnPref.setSummary(R.string.stConnectionFailed);
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                                checkNasaConnPref.setIcon(R.drawable.ic_alerts_and_states_error);
                        } else {
                            checkNasaConnPref.setSummary(R.string.stConnectionSucceeded);
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                                checkNasaConnPref.setIcon(R.drawable.ic_navigation_accept);
                        }
                    } catch (JSONException e) {
                        Toast.makeText(SettingsSupport.this.context, e.toString(), Toast.LENGTH_LONG).show();
                        e.printStackTrace();
                        checkNasaConnPref.setSummary(R.string.sCheckDBConnSummary);
                    }
                } else if (nType == 3) {//scanex
                    if (sData.length() == 0) {
                        String sMsg = "Connect failed";
                        Toast.makeText(SettingsSupport.this.context, sMsg, Toast.LENGTH_LONG).show();
                        checkScanConnPref.setSummary(R.string.stConnectionFailed);
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                            checkScanConnPref.setIcon(R.drawable.ic_alerts_and_states_error);
                    } else {
                        checkScanConnPref.setSummary(R.string.stConnectionSucceeded);
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                            checkScanConnPref.setIcon(R.drawable.ic_navigation_accept);

                        new HttpGetter(SettingsSupport.this.context, 4,
                                SettingsSupport.this.context.getString(R.string.stChecking), mReturnHandler,
                                true).execute(
                                        "http://fires.kosmosnimki.ru/SAPI/Account/Get/?CallBackName="
                                                + GetFiresService.USER_ID,
                                        sData);
                    }
                } else if (nType == 4) {//scanex detailes
                    try {
                        String sSubData = GetFiresService.removeJsonT(sData);
                        JSONObject rootobj = new JSONObject(sSubData);
                        String sStatus = rootobj.getString("Status");
                        if (sStatus.equals("OK")) {
                            JSONObject resobj = rootobj.getJSONObject("Result");
                            String sName = "";
                            if (!resobj.isNull("FullName"))
                                sName = resobj.getString("FullName");
                            String sPhone = "";
                            if (!resobj.isNull("Phone"))
                                sPhone = resobj.getString("Phone");
                            //add properties
                            if (sPhone.length() > 0) {
                                Preference PhonePref = new Preference(SettingsSupport.this.context);
                                PhonePref.setTitle(R.string.stScanexServerUserPhone);
                                PhonePref.setSummary(sPhone);
                                PhonePref.setOrder(2);
                                SettingsSupport.this.screen.addPreference(PhonePref);
                            }

                            if (sName.length() > 0) {
                                Preference NamePref = new Preference(SettingsSupport.this.context);
                                NamePref.setTitle(R.string.stScanexServerUserFullName);
                                NamePref.setSummary(sName);
                                NamePref.setOrder(2);
                                SettingsSupport.this.screen.addPreference(NamePref);
                            }

                        } else {
                            Toast.makeText(SettingsSupport.this.context, rootobj.getString("ErrorInfo"),
                                    Toast.LENGTH_LONG).show();
                        }
                    } catch (JSONException e) {
                        Toast.makeText(SettingsSupport.this.context, e.toString(), Toast.LENGTH_LONG).show();
                        e.printStackTrace();
                    }
                }
            }
        };
    };

    if (checkNasaConnPref != null)
        checkNasaConnPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference preference) {
                String sURL = mNasaServerPref.getText() + "?function=test_conn_nasa&user="
                        + mNasaServerUserPref.getText() + "&pass=" + mNasaServerPassPref.getText();
                new HttpGetter(SettingsSupport.this.context, 2,
                        SettingsSupport.this.context.getString(R.string.stChecking), mReturnHandler, true)
                                .execute(sURL);
                return true;
            }
        });

    if (checkUserConnPref != null)
        checkUserConnPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference preference) {
                String sURL = mUserServerPref.getText() + "?function=test_conn_user&user="
                        + mUserServerUserPref.getText() + "&pass=" + mUserServerPassPref.getText();
                new HttpGetter(SettingsSupport.this.context, 1,
                        SettingsSupport.this.context.getString(R.string.stChecking), mReturnHandler, true)
                                .execute(sURL);
                return true;
            }
        });

    if (checkScanConnPref != null)
        checkScanConnPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference preference) {
                //String sURL = mUserServerPref.getText() + "?function=test_conn_nasa&user=" + mUserServerUserPref.getText() + "&pass=" + mUserServerPassPref.getText();
                new ScanexHttpLogin(SettingsSupport.this.context, 3,
                        SettingsSupport.this.context.getString(R.string.stChecking), mReturnHandler, true)
                                .execute(mScanServerUserPref.getText(), mScanServerPassPref.getText());
                return true;
            }
        });
}

From source file:com.citrus.mobile.RESTclient.java

public JSONObject makeWithdrawRequest(String accessToken, double amount, String currency, String owner,
        String accountNumber, String ifscCode) {
    HttpsURLConnection conn;//from  w  w w  .ja  v  a  2 s.c  om
    DataOutputStream wr = null;
    JSONObject txnDetails = null;
    BufferedReader in = null;

    try {
        String url = urls.getString(base_url) + urls.getString(type);

        conn = (HttpsURLConnection) new URL(url).openConnection();

        //add reuqest header
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Authorization", "Bearer " + accessToken);

        StringBuffer buff = new StringBuffer("amount=");
        buff.append(amount);

        buff.append("&currency=");
        buff.append(currency);

        buff.append("&owner=");
        buff.append(owner);

        buff.append("&account=");
        buff.append(accountNumber);

        buff.append("&ifsc=");
        buff.append(ifscCode);

        conn.setDoOutput(true);
        wr = new DataOutputStream(conn.getOutputStream());

        wr.writeBytes(buff.toString());
        wr.flush();

        int responseCode = conn.getResponseCode();
        System.out.println("\nSending 'POST' request to URL : " + url);
        System.out.println("Post parameters : " + buff.toString());
        System.out.println("Response Code : " + responseCode);

        in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String inputLine;
        StringBuffer response = new StringBuffer();

        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }

        txnDetails = new JSONObject(response.toString());

    } catch (JSONException exception) {
        exception.printStackTrace();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        try {
            if (wr != null) {
                wr.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return txnDetails;
}