欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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ù)器請求發(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;
  }
  /**
   * 請求服務(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ì)有所幫助。

相關(guān)文章

  • Android實(shí)現(xiàn)緩存大圖到SD卡

    Android實(shí)現(xiàn)緩存大圖到SD卡

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)緩存大圖到SD卡,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Flutter實(shí)現(xiàn)底部和頂部導(dǎo)航欄

    Flutter實(shí)現(xiàn)底部和頂部導(dǎo)航欄

    這篇文章主要為大家詳細(xì)介紹了Flutter實(shí)現(xiàn)底部和頂部導(dǎo)航欄,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-07-07
  • Android中button點(diǎn)擊后字體的變色效果

    Android中button點(diǎn)擊后字體的變色效果

    button的點(diǎn)擊效果無疑是非常簡單的,接下來通過本文給大家介紹下如何添加button點(diǎn)擊的字體顏色變化效果,感興趣的朋友一起看看吧
    2016-10-10
  • Android實(shí)現(xiàn)簡單計(jì)算器

    Android實(shí)現(xiàn)簡單計(jì)算器

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)簡單計(jì)算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • SeekBar拖動(dòng)條的應(yīng)用實(shí)例

    SeekBar拖動(dòng)條的應(yīng)用實(shí)例

    這篇文章主要為大家詳細(xì)介紹了SeekBar拖動(dòng)條的應(yīng)用實(shí)例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-10-10
  • Android手機(jī)拍照或選取圖庫圖片作為頭像

    Android手機(jī)拍照或選取圖庫圖片作為頭像

    這篇文章主要介紹了Android手機(jī)拍照或選取圖庫圖片作為頭像的相關(guān)資料,需要的朋友可以參考下
    2015-06-06
  • Android 5.0以上Toast不顯示的解決方法

    Android 5.0以上Toast不顯示的解決方法

    最近在開發(fā)中我們經(jīng)常會(huì)在適配5.0以后的機(jī)型遇到各種各樣的問題,其中有一個(gè)不大不小的問題就是:Toast不顯示問題,這篇文章就給大家總結(jié)了Android 5.0以上Toast不顯示的原因與解決方法,有需要的朋友們可以參考借鑒,下面來一起看看吧。
    2016-11-11
  • android WakeLock使用方法代碼實(shí)例

    android WakeLock使用方法代碼實(shí)例

    WakeLock使用方法代碼實(shí)例,需要的朋友可以參考一下
    2013-06-06
  • Android應(yīng)用更新之自動(dòng)檢測版本及自動(dòng)升級

    Android應(yīng)用更新之自動(dòng)檢測版本及自動(dòng)升級

    這篇文章主要為大家詳細(xì)介紹了Android應(yīng)用更新之自動(dòng)檢測版本及自動(dòng)升級,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-09-09
  • Android開發(fā)之菜單(menu)用法實(shí)例分析

    Android開發(fā)之菜單(menu)用法實(shí)例分析

    這篇文章主要介紹了Android開發(fā)之菜單(menu)用法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Android菜單的實(shí)現(xiàn)步驟與相關(guān)操作技巧,需要的朋友可以參考下
    2017-03-03

最新評論