Android開發(fā)實(shí)現(xiàn)查詢遠(yuǎn)程服務(wù)器的工具類QueryUtils完整實(shí)例
本文實(shí)例講述了Android開發(fā)實(shí)現(xiàn)查詢遠(yuǎn)程服務(wù)器的工具類QueryUtils。分享給大家供大家參考,具體如下:
/** * 查詢遠(yuǎn)程服務(wù)器的工具 * @author chen.lin * */ public class QueryUtils { private static final String TAG = "CommonUtils"; private static QueryUtils instance; private SharedPreferences sp; private QueryUtils(Context context){ sp = context.getSharedPreferences(Constant.CONFIG, Context.MODE_PRIVATE); } public static QueryUtils getInstance(Context context){ if (instance == null) { synchronized (QueryUtils.class) { if (instance == null) { instance = new QueryUtils(context); } } } return instance; } /** * 請求服務(wù)器得到返回值 * * @param keyword * @return * @throws Exception */ public String getValue(String keyword, String reqType) throws Exception { String returnValue = null; // 使用Map封裝請求參數(shù) Map<String, String> map = new HashMap<String, String>(); map.put("reqType", reqType); map.put("localIP", sp.getString(Constant.NETIP, "")); if (keyword != null && !"".equals(keyword)) { map.put("keyword", keyword); } String url = "http://" + sp.getString(Constant.NETURL, "") + "/ymerp/" + "ServiceDocumentServlet"; returnValue = HttpUtil.postRequest(url, map); return returnValue; } /** * 請求服務(wù)器得到返回值 * * @param keyword * @return * @throws Exception */ public String queryServer(String keyword, String reqType, String servlet) throws Exception { String returnValue = null; // 使用Map封裝請求參數(shù) Map<String, String> map = new HashMap<String, String>(); map.put("reqType", reqType); map.put("localIP", sp.getString(Constant.NETIP, "")); if (!TextUtils.isEmpty(keyword)) { map.put("keyword", keyword); } String url = "http://" + sp.getString(Constant.NETURL, "") + "/ymerp/" + servlet; returnValue = HttpUtil.postRequest(url, map); return returnValue; } /** * 將json 數(shù)組轉(zhuǎn)換為Map 對象 * * @param jsonString * @return */ @SuppressLint("SimpleDateFormat") public static HashMap<String, Object> getMap(String jsonStr, String title, String timeStr) { SimpleDateFormat yymmdd = new SimpleDateFormat("yyyy-MM-dd"); JSONObject jsonObject = null; String key = null; Object value = null; try { jsonObject = new JSONObject(jsonStr); Iterator<String> it = jsonObject.keys(); HashMap<String, Object> valueMap = new HashMap<String, Object>(); while (it.hasNext()) { key = (String) it.next(); value = jsonObject.get(key); if (key != null && title.equals(key) && value != null) { String valuestr = value.toString(); if (valuestr.length() > 15) { valuestr = valuestr.substring(0, 13) + "..."; value = valuestr; } } if (key != null && timeStr.equals(key)) { try { if (value != null) { Date date = (Date) value; value = yymmdd.format(date); } else { valueMap.put(key, ""); } } catch (Exception e) { } } if (key != null && value != null) { valueMap.put(key, value); } } return valueMap; } catch (JSONException e) { e.printStackTrace(); } return null; } }
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android操作SQLite數(shù)據(jù)庫技巧總結(jié)》、《Android操作json格式數(shù)據(jù)技巧總結(jié)》、《Android數(shù)據(jù)庫操作技巧總結(jié)》、《Android文件操作技巧匯總》、《Android編程開發(fā)之SD卡操作方法匯總》、《Android資源操作技巧匯總》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計(jì)有所幫助。
- android中Intent傳值與Bundle傳值的區(qū)別詳解
- android教程之intent的action屬性使用示例(intent發(fā)短信)
- android中intent傳遞list或者對象的方法
- Android Intent的幾種用法詳細(xì)解析
- Android組件間通信--深入理解Intent與IntentFilter
- Android Intent啟動(dòng)別的應(yīng)用實(shí)現(xiàn)方法
- 詳解Android中Intent的使用方法
- Android系列之Intent傳遞對象的幾種實(shí)例方法
- Android利用Intent啟動(dòng)和關(guān)閉Activity
- Android開發(fā)中超好用的正則表達(dá)式工具類RegexUtil完整實(shí)例
- Android開發(fā)實(shí)現(xiàn)的Intent跳轉(zhuǎn)工具類實(shí)例
相關(guān)文章
Flutter實(shí)現(xiàn)底部和頂部導(dǎo)航欄
這篇文章主要為大家詳細(xì)介紹了Flutter實(shí)現(xiàn)底部和頂部導(dǎo)航欄,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07Android中button點(diǎn)擊后字體的變色效果
button的點(diǎn)擊效果無疑是非常簡單的,接下來通過本文給大家介紹下如何添加button點(diǎn)擊的字體顏色變化效果,感興趣的朋友一起看看吧2016-10-10SeekBar拖動(dòng)條的應(yīng)用實(shí)例
這篇文章主要為大家詳細(xì)介紹了SeekBar拖動(dòng)條的應(yīng)用實(shí)例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-10-10Android應(yīng)用更新之自動(dòng)檢測版本及自動(dòng)升級
這篇文章主要為大家詳細(xì)介紹了Android應(yīng)用更新之自動(dòng)檢測版本及自動(dòng)升級,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-09-09Android開發(fā)之菜單(menu)用法實(shí)例分析
這篇文章主要介紹了Android開發(fā)之菜單(menu)用法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Android菜單的實(shí)現(xiàn)步驟與相關(guān)操作技巧,需要的朋友可以參考下2017-03-03