最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android開發(fā)實(shí)現(xiàn)查詢遠(yuǎn)程服務(wù)器的工具類QueryUtils完整實(shí)例

 更新時(shí)間:2017年11月11日 12:13:08   作者:LovooGod  
這篇文章主要介紹了Android開發(fā)實(shí)現(xiàn)查詢遠(yuǎn)程服務(wù)器的工具類QueryUtils,涉及Android服務(wù)器請(qǐng)求發(fā)送、接收、數(shù)據(jù)交互等相關(guān)操作技巧,需要的朋友可以參考下

本文實(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;
  }
  /**
   * 請(qǐng)求服務(wù)器得到返回值
   *
   * @param keyword
   * @return
   * @throws Exception
   */
  public String getValue(String keyword, String reqType) throws Exception {
    String returnValue = null;
    // 使用Map封裝請(qǐng)求參數(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;
  }
  /**
   * 請(qǐng)求服務(wù)器得到返回值
   *
   * @param keyword
   * @return
   * @throws Exception
   */
  public String queryServer(String keyword, String reqType, String servlet) throws Exception {
    String returnValue = null;
    // 使用Map封裝請(qǐng)求參數(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 對(duì)象
   *
   * @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é)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

永城市| 鲜城| 吴堡县| 合山市| 孟州市| 南平市| 晋中市| 宝兴县| 泰州市| SHOW| 山东省| 宜川县| 崇阳县| 克拉玛依市| 桐梓县| 即墨市| 巴南区| 华安县| 平远县| 白银市| 马边| 汕头市| 屏南县| 长葛市| 辰溪县| 大余县| 山东省| 津市市| 炎陵县| 新沂市| 常熟市| 伽师县| 岳阳市| 克拉玛依市| 手游| 杨浦区| 凤冈县| 会昌县| 改则县| 朝阳市| 台山市|