public void readSetting() {
    // ��ȡ����
    ContentResolver resolver = getContentResolver();
    Cursor cursor = null;
    boolean found = false;
    Uri uri = Uri.parse(SETTING_URI);

    cursor = resolver.query(uri, SettingEntity.projection, null, null, null);
    if (cursor != null) {
      if (cursor.moveToFirst()) {
        found = true;
      }
    }

    // ���û�ҵ����ã��趨Ĭ��ֵ
    if (!found) {
      // ��������Ĭ��ֵ
      ContentValues values = new ContentValues();
      mSettingEntity.setUpdateWhenOpen(0);
      mSettingEntity.setUpdateRegularly(1);
      mSettingEntity.setUpdateInterval(1);
      mSettingEntity.setSoundEnable(0);

      values.put(SettingEntity.UPDATE_WHEN_OPEN, mSettingEntity.getUpdateWhenOpen());
      values.put(SettingEntity.UPDATE_REGULARLY, mSettingEntity.getUpdateRegularly());
      values.put(SettingEntity.UPDATE_INTERVAL, mSettingEntity.getUpdateInterval());
      values.put(SettingEntity.SOUND_ENABLE, mSettingEntity.getSoundEnable());
      resolver.insert(uri, values);
    } else {
      mSettingEntity.setUpdateWhenOpen(cursor.getInt(0));
      mSettingEntity.setUpdateRegularly(cursor.getInt(1));
      mSettingEntity.setUpdateInterval(cursor.getInt(2));
      mSettingEntity.setSoundEnable(cursor.getInt(3));
    }

    if (cursor != null) {
      cursor.close();
    }
  }
  @Override
  protected void onHandleIntent(Intent arg0) {

    //     synchronized (sLock) {
    long now = System.currentTimeMillis();

    readSetting();

    if (true) {
      mPostalCode = arg0.getStringExtra("postalCode");
      mUserId = arg0.getIntExtra("userId", 0);
      mForcedUpdate = arg0.getIntExtra("forcedUpdate", 0);

      if (mPostalCode == null) {
        mPostalCode = "all";
      }

      Log.v(TAG, "onStartCommand mPostalCode = " + mPostalCode + ", mUserId = " + mUserId);

      isThreadRun = true;
      // new Thread(this).start();
    }

    if (mPostalCode.equals("bootup")) {
    } else if (mPostalCode.equals("all")) {
      ContentResolver resolver = this.getContentResolver();
      Cursor cursor = null;
      int i = 0;
      String[] postalcode = null;
      int[] id = null;
      Uri uri = Uri.parse("content://com.cooee.app.cooeejewelweather3D.dataprovider/postalCode");
      cursor = resolver.query(uri, PostalCodeEntity.projection, null, null, null);
      if (cursor != null) {
        int count = cursor.getCount();
        postalcode = new String[count];
        id = new int[count];
        while (cursor != null && cursor.moveToNext()) {
          postalcode[i] = cursor.getString(0);
          id[i] = cursor.getInt(1);
          i++;
        }
        addWidgetIDs(id);
        i = 0;
        while (hasMoreWidgetIDs()) {
          int widgetid = nextWidgetIDs();
          boolean ignored = false;
          allUserId = id[i];
          allPostalCode = postalcode[i];
          Log.v(
              TAG,
              "allUserId = "
                  + id[i]
                  + " allPostalCode = "
                  + postalcode[i]
                  + " WidgetIDs = "
                  + widgetid);
          for (int j = 0; j < i; j++) {
            if (postalcode[i].equals(postalcode[j])) {
              ignored = true;
              break;
            }
          }
          if (!ignored) {
            Uri data_uri =
                Uri.parse(
                    "content://com.cooee.app.cooeejewelweather3D.dataprovider/weather/"
                        + postalcode[i]);
            weatherwebservice.updateWeatherData(this, data_uri);
            allSendBroadcast();
          }
          i++;
        }
      }
      cursor.close();
    } else {
      boolean needUpdate = true;
      if (mForcedUpdate == 0) {
        ContentResolver resolver = this.getContentResolver();
        Cursor cursor = null;
        String selection = null;
        Uri uri =
            Uri.parse("content://" + weatherdataprovider.AUTHORITY + "/weather/" + mPostalCode);
        selection = weatherdataentity.POSTALCODE + "=" + "'" + mPostalCode + "'";
        cursor = resolver.query(uri, weatherdataentity.projection, selection, null, null);
        if (cursor != null) {
          if (cursor.moveToFirst()) {
            long lastUpdateTime = cursor.getLong(10);
            if (now - lastUpdateTime < mSettingEntity.getUpdateInterval()) {
              needUpdate = false;
            }
          }
          cursor.close();
        }
      }

      Log.v(TAG, "needUpdate = " + needUpdate);
      if (needUpdate) {
        Uri uri =
            Uri.parse("content://" + weatherdataprovider.AUTHORITY + "/weather/" + mPostalCode);
        weatherwebservice.updateWeatherData(this, uri);
      } else {
        weatherwebservice.Update_Result_Flag = FLAG_UPDATE.AVAILABLE_DATA;
      }

      mySendBroadcast();
    }

    if (mSettingEntity.getUpdateRegularly() != 0) {
      Time time = new Time();
      long interval = mSettingEntity.getUpdateInterval();
      if (interval < 60 * 1000 * 60 * 6) interval = 60 * 1000 * 60 * 6;

      if (weatherwebservice.Update_Result_Flag != FLAG_UPDATE.UPDATE_SUCCES) {
        interval = 60 * 1000 * 10;
      }
      time.set(now + interval);
      // time.set(now + 2 * 60 * 1000);
      long nextUpdate = time.toMillis(true);

      Intent updateIntent = new Intent(ACTION_UPDATE_ALL);
      updateIntent.setClass(this, weatherDataService.class);

      PendingIntent pendingIntent = PendingIntent.getService(this, 0, updateIntent, 0);

      // Schedule alarm, and force the device awake for this update
      AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
      alarmManager.set(AlarmManager.RTC_WAKEUP, nextUpdate, pendingIntent);
    }

    isThreadRun = false;

    // No updates remaining, so stop service
    stopSelf();
    //     }

  }