Пример #1
0
  public void readMessages(Activity act, TextView tempr, TextView dateV) {

    // Getting all messages from inbox (added also permission for reading in
    // Manifest)
    Cursor cursor =
        act.getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);

    // Here message body of "fromNumber" will be stored
    String body = "";
    // StringBuilder number = new StringBuilder(""); here can be number
    // stored

    // must check the result to prevent exception
    if (cursor.moveToFirst()) {
      // Starting from last received messages and going through
      for (int i = 0; i < cursor.getCount(); i++) {
        // Checking if message is received from "fromNumber"
        if (fromNumber.equals(
            cursor.getString(cursor.getColumnIndexOrThrow("address")).toString())) {
          // If yes taking that message body
          body = cursor.getString(cursor.getColumnIndexOrThrow("body")).toString();
          // Check if body has "T=" string, take information from such
          // message
          if (body.indexOf("T=") > -1) {
            // Take temperature information from text message
            body = body.substring(body.indexOf("T=") + 2, body.indexOf("T=") + 6);
            tempr.setText(body);

            // If yes taking that message date
            String date = cursor.getString(cursor.getColumnIndexOrThrow("date")).toString();
            Date smsDay = new Date(Long.valueOf(date));
            Time smsTime = new Time(Long.valueOf(date));
            String smsReceived = smsDay.toString() + " - " + smsTime.toString();
            dateV.setText(smsReceived);
            break;
          } else {
            cursor.moveToNext();
          }
        } else {
          cursor.moveToNext();
        }
      }
    } else {
      Toast.makeText(act.getApplicationContext(), "SMS not found", Toast.LENGTH_LONG).show();
    }
  }
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == Activity.RESULT_OK) {
      String sdStatus = Environment.getExternalStorageState();
      if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) { // 检测sd是否可用
        Log.i("TestFile", "SD card is not avaiable/writeable right now.");
        return;
      }
      String name =
          new DateFormat().format("yyyyMMdd_hhmmss", Calendar.getInstance(Locale.CHINA)) + ".jpg";
      Toast.makeText(this, name, Toast.LENGTH_LONG).show();
      Bundle bundle = data.getExtras();
      Bitmap bitmap = (Bitmap) bundle.get("data"); // 获取相机返回的数据,并转换为Bitmap图片格式

      FileOutputStream b = null;
      File file = new File("/sdcard/myImage/");
      if (!file.exists()) file.mkdirs(); // 创建文件夹

      String fileName = "/sdcard/myImage/" + name;
      File photofile = new File(fileName);
      if (!photofile.exists()) {
        try {
          photofile.createNewFile();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      try {
        b = new FileOutputStream(photofile);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, b); // 把数据写入文件
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        try {
          b.flush();
          b.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      // 动态的改变gridview中的一个Item的内容
      bitmapList.set(currentIndex, bitmap);
      myGalleryAdapter.notifyDataSetChanged();
      updatePhoto(
          Long.valueOf(phoneNumberToId.get(phoneNumber.get(currentIndex))), bitmapToBytes(bitmap));
      //            ((ImageView) findViewById(R.id.imageView)).setImageBitmap(bitmap);//
      // 将图片显示在ImageView里
      Intent intent = new Intent(ContactActivity.this, ContactActivity.class);
      this.startActivity(intent);
      this.finish();
    }
  }
  public TaobaoItemRichInfo parseRichItemsJSON(String itemId) throws IOException {
    TaobaoItemBasicInfo taobaoItemBasicInfo = new TaobaoItemBasicInfo();
    TaobaoItemRichInfo taobaoItemRichInfo = new TaobaoItemRichInfo();
    String itemBasicJson = "";
    String itemRichJson = "";
    if (Helper.checkConnection(context)) {
      try {
        int timeout = 30000;
        Map param = new HashMap<String, String>();
        param.put("securityKey", SecurityKey.getKey());
        String itemBasicInfoUrl = Constants.SERVER_DOMAIN + "/api/item/basicinfo/" + itemId;
        String itemRichInfoUrl = Constants.SERVER_DOMAIN + "/api/item/picwordinfo/" + itemId;
        itemBasicJson = WebUtils.doPost(itemBasicInfoUrl, param, timeout, timeout);
        itemRichJson = WebUtils.doPost(itemRichInfoUrl, param, timeout, timeout);
      } catch (IOException e) {
        Log.e("IOException is : ", e.toString());
        e.printStackTrace();
        return taobaoItemRichInfo;
      }
    }
    try {
      if (null != itemBasicJson && !"".equals(itemBasicJson)) {
        JSONObject jsonObject = new JSONObject(itemBasicJson);
        String result = jsonObject.has("ret") ? jsonObject.get("ret").toString() : null;
        if (result == null || !result.contains("SUCCESS")) {
          return taobaoItemRichInfo;
        }
        JSONObject dateJsonObject = jsonObject.getJSONObject("data");
        String sellerJson = dateJsonObject.getString("seller");
        String rateJson = dateJsonObject.getString("rateInfo");
        JSONArray apiStackJsonArray = dateJsonObject.getJSONArray("apiStack");
        if (apiStackJsonArray == null || apiStackJsonArray.length() == 0) {
          return taobaoItemRichInfo;
        }
        JSONObject esiInfoObject = new JSONObject(apiStackJsonArray.get(0).toString());
        JSONObject apiStackDataObject =
            new JSONObject(esiInfoObject.getString("value")).getJSONObject("data");
        JSONObject itemInfoObject = dateJsonObject.getJSONObject("itemInfoModel");

        JSONArray picArray = itemInfoObject.getJSONArray("picsPath");
        // 这里为商品列表页展示数据使用,所以只展示一张图片
        taobaoItemBasicInfo.setItemId(Long.valueOf(itemId));
        taobaoItemBasicInfo.setTitle(itemInfoObject.getString("title"));
        taobaoItemBasicInfo.setFavcount(itemInfoObject.getString("favcount"));
        taobaoItemBasicInfo.setSku(itemInfoObject.getBoolean("sku"));
        taobaoItemBasicInfo.setItemUrl(itemInfoObject.getString("itemUrl"));
        taobaoItemBasicInfo.setLocation(itemInfoObject.getString("location"));
        ArrayList picsPath = new ArrayList<String>();
        for (int i = 0; i < picArray.length(); i++) {
          picsPath.add(picArray.getString(i));
        }
        taobaoItemBasicInfo.setPicsPath(picsPath);
        taobaoItemBasicInfo.setSellerInfo(new SellerInfo(sellerJson));
        taobaoItemBasicInfo.setRateInfo(new RateInfo(rateJson));

        if (taobaoItemBasicInfo.getSku()) {
          JSONObject skuModelObject = dateJsonObject.getJSONObject("skuModel");
          taobaoItemBasicInfo.setSkuModel(new SkuModel(skuModelObject, apiStackDataObject));
        } else {
          taobaoItemBasicInfo.setSkuModel(new SkuModel(null, apiStackDataObject));
        }
      }
      if (null != itemRichJson && !"".equals(itemRichJson)) {
        JSONObject jsonObject = new JSONObject(itemRichJson);
        String result = jsonObject.get("ret").toString();
        if (result == null || !result.contains("SUCCESS")) {
          return taobaoItemRichInfo;
        }
        JSONArray imagesJsonArray = jsonObject.getJSONObject("data").getJSONArray("images");
        List imagesList = new ArrayList();
        for (int i = 0; i < imagesJsonArray.length(); i++) {
          imagesList.add(imagesJsonArray.get(i).toString());
        }
        taobaoItemRichInfo.setImageList(imagesList);
      }
      taobaoItemRichInfo.setBasicInformation(taobaoItemBasicInfo);
    } catch (JSONException e) {
      e.printStackTrace();
    }
    return taobaoItemRichInfo;
  }
Пример #4
0
 private long readTimeMillis() {
   TimeUnit selectedUnit = units[spTimeUnit.getSelectedItemPosition()];
   long value = Long.valueOf(etxtTime.getText().toString());
   return selectedUnit.toMillis(value);
 }