Пример #1
0
 private String getNameFromContentUri(Uri contentUri) {
   final String name;
   final Cursor returnCursor =
       application.getContentResolver().query(contentUri, null, null, null, null);
   if (returnCursor != null && returnCursor.moveToFirst()) {
     name = returnCursor.getString(returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
     returnCursor.close();
   } else {
     name = null;
   }
   return name;
 }
Пример #2
0
  public static void checkAndDisplay(final MapActivity mapActivity) {
    if (mBannerVisible) {
      showDiscountBanner(mapActivity, mTitle, mDescription, mIcon, mUrl);
    }
    OsmandApplication app = mapActivity.getMyApplication();
    if (System.currentTimeMillis() - mLastCheckTime < 1000 * 60 * 60 * 24
        || !app.getSettings().isInternetConnectionAvailable()
        || app.getSettings().NO_DISCOUNT_INFO.get()) {
      return;
    }
    mLastCheckTime = System.currentTimeMillis();
    final Map<String, String> pms = new LinkedHashMap<>();
    pms.put("version", Version.getFullVersion(app));
    pms.put("nd", app.getAppInitializer().getFirstInstalledDays() + "");
    pms.put("ns", app.getAppInitializer().getNumberOfStarts() + "");
    try {
      pms.put("aid", Secure.getString(app.getContentResolver(), Secure.ANDROID_ID));
    } catch (Exception e) {
      e.printStackTrace();
    }
    new AsyncTask<Void, Void, String>() {

      @Override
      protected String doInBackground(Void... params) {
        try {
          String res =
              AndroidNetworkUtils.sendRequest(
                  mapActivity.getMyApplication(),
                  URL,
                  pms,
                  "Requesting discount info...",
                  false,
                  false);
          return res;
        } catch (Exception e) {
          logError("Requesting discount info error: ", e);
          return null;
        }
      }

      @Override
      protected void onPostExecute(String response) {
        if (response != null) {
          processDiscountResponse(response, mapActivity);
        }
      }
    }.execute();
  }