private void parseJson(String json) {
    mThread.interrupt();
    Looper.prepare();
    try {

      JSONObject obj = new JSONObject(json);
      String updateMessage = obj.getString(Constants.APK_UPDATE_CONTENT);
      String apkUrl = obj.getString(Constants.APK_DOWNLOAD_URL);
      int apkCode = obj.getInt(Constants.APK_VERSION_CODE);

      int versionCode =
          mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionCode;

      if (apkCode > versionCode) {
        if (mTypeOfNotice == NOTICE_NOTIFICATION) {
          showNotification(updateMessage, apkUrl);
        } else if (mTypeOfNotice == NOTICE_DIALOG) {
          showDialog(updateMessage, apkUrl);
        }
      } else {
        // Toast.makeText(mContext, mContext.getString(R.string.app_no_new_update),
        // Toast.LENGTH_SHORT).show();
      }

    } catch (PackageManager.NameNotFoundException ignored) {
    } catch (JSONException e) {
      Log.e(TAG, "parse json error", e);
    }
  }
예제 #2
0
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    try {
      FragmentActivity activity = getActivity();
      PackageInfo packageInfo =
          activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);
      mVersion.setText(packageInfo.versionName);
    } catch (PackageManager.NameNotFoundException e) {
      e.printStackTrace();
    }
  }