Exemplo n.º 1
0
  public void cargar() {

    BaseHelper baseHelper = new BaseHelper(this, "Demodb", null, 1);
    SQLiteDatabase db = baseHelper.getWritableDatabase();
    if (db != null) {

      Cursor c = db.rawQuery("select * from personas", null);
      int cantidad = c.getCount();
      String[] arreglo = new String[cantidad];
      int i = 0;
      if (c.moveToFirst()) {
        do {

          String linea =
              c.getInt(0)
                  + " "
                  + c.getString(1)
                  + " "
                  + c.getString(2)
                  + " "
                  + c.getString(3)
                  + " "
                  + c.getString(4);
          arreglo[i] = linea;
          i++;

        } while (c.moveToNext());
      }

      ArrayAdapter<String> adapter =
          new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arreglo);
      ListView lista = (ListView) findViewById(R.id.lista);
      lista.setAdapter(adapter);
    }
  }
Exemplo n.º 2
0
 public static void main(String[] args) {
   BaseHelper helper;
   helper = new EventsHelper();
   List<Events> objects = helper.fetchAll();
   for (Events e : objects) {
     System.out.println(e.getName());
   }
 }
Exemplo n.º 3
0
  /**
   * 发�?和接收数�?
   *
   * @param strReqData 请求数据
   * @param strUrl 请求地址
   * @return
   */
  public String SendAndWaitResponse(String strReqData, String strUrl) {
    //
    detectProxy();

    String strResponse = null;
    // ArrayList<BasicNameValuePair> pairs = new ArrayList<BasicNameValuePair>();
    // pairs.add(new BasicNameValuePair("requestData", strReqData));

    HttpURLConnection httpConnect = null;
    StringEntity p_entity;
    OutputStream os = null;
    try {
      // p_entity = new UrlEncodedFormEntity(pairs, "utf-8");
      p_entity = new StringEntity(strReqData, "utf-8");
      URL url = new URL(strUrl);

      if (mProxy != null) {
        httpConnect = (HttpURLConnection) url.openConnection(mProxy);
      } else {
        httpConnect = (HttpURLConnection) url.openConnection();
      }
      httpConnect.setConnectTimeout(connectTimeout);
      httpConnect.setReadTimeout(readTimeout);
      httpConnect.setDoOutput(true);
      httpConnect.addRequestProperty(
          "Content-type", "application/x-www-form-urlencoded;charset=utf-8");

      httpConnect.connect();

      os = httpConnect.getOutputStream();
      p_entity.writeTo(os);
      os.flush();

      InputStream content = httpConnect.getInputStream();
      strResponse = BaseHelper.convertStreamToString(content);
      BaseHelper.log(TAG, "response " + strResponse);
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      if (os != null) {
        try {
          os.close();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
      if (httpConnect != null) {
        httpConnect.disconnect();
      }
    }

    return strResponse;
  }
  public boolean detectMobile_sp(String pluginName, String packName) {
    boolean isMobile_spExist = isMobile_spExist(packName);
    if (!isMobile_spExist) {
      // get the cacheDir.
      File cacheDir = mContext.getCacheDir();
      final String cachePath = cacheDir.getAbsolutePath() + "/temp.apk";

      final String apkName = pluginName;
      //
      // 捆绑安装
      retrieveApkFromAssets(mContext, pluginName /*Constants.ALIPAY_PLUGIN_NAME*/, cachePath);

      mProgress = BaseHelper.showProgress(mContext, null, "正在检测安全支付服务版本", false, true);

      new Thread(
              new Runnable() {
                public void run() {
                  //
                  // �?��是否有新的版本�?
                  PackageInfo apkInfo = getApkInfo(mContext, cachePath);
                  String newApkdlUrl = "";
                  Message msg = new Message();
                  if (apkName.equals(Constants.PAY_PLUGIN_NAME)) {
                    newApkdlUrl = checkNewUpdateForHuafubao(apkInfo);
                    msg.what = MSG_WHAT;
                  } else {
                    newApkdlUrl = checkNewUpdate(apkInfo);
                    msg.what = AlixId.RQF_INSTALL_CHECK;
                  }

                  //
                  // 动�?下载
                  if (newApkdlUrl != null) retrieveApkFromNet(mContext, newApkdlUrl, cachePath);

                  // send the result back to caller.
                  //					Message msg = new Message();
                  //					msg.what = AlixId.RQF_INSTALL_CHECK;
                  msg.obj = cachePath;
                  mHandler.sendMessage(msg);
                }
              })
          .start();
    }
    // else ok.

    return isMobile_spExist;
  }
  /** add by yejc 20130527 end */
  public JSONObject sendRequest(final String content, String url) {
    NetworkManager nM = new NetworkManager(this.mContext);

    JSONObject jsonResponse = null;
    try {
      String response = null;
      synchronized (nM) {
        response = nM.SendAndWaitResponse(content, url /*Constants.server_url*/);
      }

      jsonResponse = new JSONObject(response);
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (jsonResponse != null) BaseHelper.log(TAG, jsonResponse.toString());

    return jsonResponse;
  }