@Override protected String doInBackground(String... params) { String result = ""; HttpParams myParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(myParams, 10000); HttpConnectionParams.setSoTimeout(myParams, 10000); HttpClient httpclient = new DefaultHttpClient(myParams); // String url = "http://development.ayowes.com/pedobackend/public/api/activitieslog"; String url = params[0]; try { JSONArray dataArray = new JSONArray(); for (String[] row : answer) { JSONObject jsonObject = new JSONObject(); try { // jsonObject.put("TR_ID",trainingID); jsonObject.put("QUIZ_Q_ID", row[0]); jsonObject.put("OPT", row[1]); jsonObject.put("OPT_TEXT", row[2]); } catch (JSONException e) { e.printStackTrace(); } dataArray.put(jsonObject); } JSONObject dataToServer = new JSONObject(); try { dataToServer.put("user_id", session.getuserid()); dataToServer.put("device_id", session.getdeviceid()); dataToServer.put("trueanswer", trueAnswer); dataToServer.put("falseanswer", falseAnswer); dataToServer.put("score", score); dataToServer.put("quiz_id", quizID); dataToServer.put("data", dataArray); } catch (JSONException e) { e.printStackTrace(); } String json = dataToServer.toString(); Log.e("questionnaire", json); HttpPost httppost = new HttpPost(url); httppost.setHeader("Content-type", "application/json"); StringEntity se = new StringEntity(json); // se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); httppost.setEntity(se); HttpResponse response = httpclient.execute(httppost); result = EntityUtils.toString(response.getEntity()); Log.d("pushdata", result); } catch (ClientProtocolException e) { Log.e("pushdata", e.getMessage()); } catch (ConnectTimeoutException e) { Log.e("pushdata", "timeout"); } catch (IOException e) { Log.e("pushdata", "ioexception"); } return result; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_individual_chat); context = this; dbmsg = new DbMessage(this); etmessage = (EmojiconEditText) findViewById(R.id.etmessage); btnsend = (ImageButton) findViewById(R.id.btnsend); btnfile = (Button) findViewById(R.id.btnfile); btnsmiley = (ImageView) findViewById(R.id.btnsmiley); list = (ListView) findViewById(R.id.list); registerForContextMenu(list); isopened = true; DataManager.isindividualopen = isopened; registerReceiver(broadcastReceiver, new IntentFilter("CHAT_MESSAGE_RECEIVED")); session = new SessionManager(this); userid = session.getuserid(); senderid = DataManager.senderid; deviceid = session.getdeviceid(); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); LayoutInflater mInflater = LayoutInflater.from(this); View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null); txtalert = (TextView) mCustomView.findViewById(R.id.txtalert); pic = (RoundedImageView) mCustomView.findViewById(R.id.img); txtname = (TextView) mCustomView.findViewById(R.id.txtname); toolbar.addView(mCustomView); txtalert = (TextView) findViewById(R.id.txtalert); pic = (RoundedImageView) findViewById(R.id.img); txtname = (TextView) findViewById(R.id.txtname); txtname.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent i = new Intent(IndividualChat.this, UserProfile.class); DataManager.profileid = senderid; startActivity(i); } }); if (DataManager.fullname.length() > 0) { txtname.setText("" + DataManager.fullname); } else { name = dbmsg.getname(senderid); DataManager.fullname = name; txtname.setText("" + name); } new getuserprofile().execute(); myuserid = session.getuserid(); dbmsg.updateindividualseen(senderid); int seencount = dbmsg.getunseeenindividual(senderid, "no"); btnsend.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub addNewMessage(); } }); getmessage(); btnfile.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub selectImage(); } }); smileyintegration(); }