コード例 #1
0
  private void startDownloadOfMagazineFromResponse(HttpResponse response) {
    String tempURL = null;
    if (null == response) {
      showAlertDialog(DOWNLOAD_ALERT);
      Log.w(TAG, "download response was null");
      return;
    }

    tempURL = getTempURL(response);
    if (tempURL == null) {
      // Toast.makeText(getContext(), "Download failed", Toast.LENGTH_SHORT).show();
      showAlertDialog(DOWNLOAD_ALERT);
      return;
    }
    if (getIntent().getExtras() != null) {
      MagazineDownloadService.startMagazineDownload(
          this, new Magazine(fileName, title, subtitle, null, this), true, tempURL);
      Intent intent = new Intent(getContext(), DownloadMagazineActivity.class);
      intent.putExtra(BillingActivity.FILE_NAME_KEY, fileName);
      intent.putExtra(BillingActivity.SUBTITLE_KEY, subtitle);
      intent.putExtra(BillingActivity.TITLE_KEY, title);
      intent.putExtra(BillingActivity.IS_SAMPLE_KEY, false);
      startActivity(intent);
      setResult(RESULT_OK);
      finish();
    } else {
      Toast.makeText(this, "Purchase successful", Toast.LENGTH_LONG).show();
    }
    finish();
  }
コード例 #2
0
  // This is to check subscription status when a push notification is sent for a new issue
  // If something goes wrong, don't download the issue, just show a notification
  public static boolean backgroundCheckForValidSubscriptionFailFast(
      Context context, String fileName, String title, String subtitle) {

    String prefSubscrCode = getSavedSubscriberCode(context);

    if (prefSubscrCode != null) {
      String subscriptionCodeQuery = buildSubscriptionCodeQuery(context, prefSubscrCode, fileName);
      HttpClient httpclient = new DefaultHttpClient();
      try {
        HttpGet httpget = new HttpGet(subscriptionCodeQuery);
        HttpClientParams.setRedirecting(httpclient.getParams(), false);
        HttpResponse httpResponse = httpclient.execute(httpget);
        int responseCode = httpResponse.getStatusLine().getStatusCode();
        if (responseCode == UNAUTHORIZED_CODE) {
        } else if (responseCode == UNAUTHORIZED_ISSUE) {
        } else if (responseCode == UNAUTHORIZED_DEVICE) {
        } else {
          String tempURL = getTempURL(httpResponse);
          if (tempURL != null) {
            MagazineDownloadService.startMagazineDownload(
                context, new Magazine(fileName, title, subtitle, null, context), true, tempURL);
            return true;
          }
        }
      } catch (IllegalArgumentException e) {
        Log.e(TAG, "URI is malformed", e);
      } catch (ClientProtocolException e) {
        Log.e(TAG, "Download failed", e);
      } catch (IOException e) {
        Log.e(TAG, "Download failed", e);
      }
      return false;
    }

    String prefUsername = getSavedUsername(context);

    if (prefUsername != null) {
      String prefPassword = getSavedPassword(context);
      String usernamePasswordLoginQuery =
          buildUsernamePasswordLoginQuery(context, prefUsername, prefPassword, fileName);
      HttpClient httpclient = new DefaultHttpClient();
      try {
        HttpGet httpget = new HttpGet(usernamePasswordLoginQuery);
        HttpClientParams.setRedirecting(httpclient.getParams(), false);
        HttpResponse httpResponse = httpclient.execute(httpget);
        int responseCode = httpResponse.getStatusLine().getStatusCode();
        if (responseCode == UNAUTHORIZED_CODE) {
        } else if (responseCode == UNAUTHORIZED_ISSUE) {
        } else if (responseCode == UNAUTHORIZED_DEVICE) {
        } else {
          String tempURL = getTempURL(httpResponse);
          if (tempURL != null) {
            MagazineDownloadService.startMagazineDownload(
                context, new Magazine(fileName, title, subtitle, null, context), true, tempURL);
            return true;
          }
        }
      } catch (IllegalArgumentException e) {
        Log.e(TAG, "URI is malformed", e);
      } catch (ClientProtocolException e) {
        Log.e(TAG, "Download failed", e);
      } catch (IOException e) {
        Log.e(TAG, "Download failed", e);
      }
      return false;
    }
    return false;
  }