1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | void Connect() { try { SSLSocketFactory sf = getSSLSocketFactory(); HttpsURLConnection.setDefaultSSLSocketFactory(sf); HttpsURLConnection.setDefaultHostnameVerifier(new TrustAnyHostnameVerifier()); try { URL url = new URL(strURL); conn = (HttpsURLConnection) url.openConnection(); //set userID/userPassword for the IBM Systems Director authentication. Authenticator.setDefault(new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication (username, password.toCharArray()); } }); conn.connect(); this.responseCode = conn.getResponseCode(); //get response result from the connection BufferedReader br; String line ; try { br = new BufferedReader(new InputStreamReader(conn.getInputStream())); while( (line = br.readLine()) != null ){ responseResult += line + "\n"; } br.close(); } catch (IOException e) { e.printStackTrace(); } //get sub response result in the form of array "[...]" from the response info int start = responseResult.indexOf("["); int end = responseResult.lastIndexOf("]") + 1; this.resultArray = responseResult.substring(start, end); }catch (MalformedURLException e) { e.printStackTrace(); }catch(IOException e){ e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.propertylist); ListView listView = (ListView) findViewById(R.id.eventdetailslistview); registerForContextMenu(listView); final TextView tv0 = (TextView) findViewById(R.id.edtitle); tv0.setText(this.getString(R.string.event_detail_page_title)); final TextView tv = (TextView) findViewById(R.id.eventdetailshostname); tv.setText(_resName); HttpResponse resp; JSONObject jo; JSONObject objTime; try { resp = s_httpFecther.sendRequest(_resUri, HttpMethodType.GET, null); jo = new JSONObject(HttpFetcher.getContentAsString(resp)); // Generate dynamic array and fill data into the array ArrayList<HashMap<String, Object>> eventlistItem=\ new ArrayList<HashMap<String, Object>>(); HashMap<String, Object> map; map = new HashMap<String, Object>(); map.put("key", "ComponentType"); map.put("value", jo.getString("ComponentType")); eventlistItem.add(map); map = new HashMap<String, Object>(); map.put("key", "Severity"); map.put("value", jo.getString("Severity")); eventlistItem.add(map); map = new HashMap<String, Object>(); map.put("key", "EventText"); map.put("value", jo.getString("EventText")); eventlistItem.add(map); objTime = new JSONObject(jo.getString("GeneratedDate")); Date d = new Date(); d.setTime(Long.parseLong(objTime.getString("Date").toString())); HashMap<String, Object> map5 = new HashMap<String, Object>(); map5.put("key", "GeneratedTime"); map5.put("value", d.toLocaleString()); eventlistItem.add(map5); // Generate adapter final SimpleAdapter propertylistItemAdapter= new SimpleAdapter(getBaseContext(), eventlistItem, R.layout.propertylistitem, new String[] { "key", "value" }, new int[] { R.id.key, R.id.value }); listView.setAdapter(propertylistItemAdapter); } catch (JSONException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |