Results 1 to 2 of 2
  1. #1
    Seated is offline Member
    Join Date
    Feb 2014
    Posts
    2
    Rep Power
    0

    Question Trying to download webpage source, but code requires a minimal SDK version 3 whereas

    I'm trying to download a web page source within android using Java, but else where in my program the minimum requirement for SDK within the Android manifest needs to be set at 11 but the below code (to download source) will only work when minimum SDK version is set to 3.

    Is there any changes you would suggest I make to the below code

    Java Code:
     public void getHtml() throws ClientProtocolException, IOException
    {
        HttpClient httpClient = new DefaultHttpClient();
        HttpContext localContext = new BasicHttpContext();
        HttpGet httpGet = new HttpGet("http://www.google.com");
        HttpResponse response = httpClient.execute(httpGet, localContext);
        String result = "";
    
        BufferedReader reader = new BufferedReader(
            new InputStreamReader(
              response.getEntity().getContent()
            )
          );
    
        String line = null;
        while ((line = reader.readLine()) != null){
          result += line + "\n";
          Toast.makeText(activity.this, line.toString(), Toast.LENGTH_LONG).show();
    
        }
    
    }
    Code above requires minmium SDK version 3

    Rest of code requires minimum SDK version 11


    When I change minimum SDK in android manifest to 11 above code won't work


    (By won't work, I mean I get the error "Unfortunately Test has stopped" and then the app closes)
    Last edited by Seated; 02-18-2014 at 04:01 AM.

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Trying to download webpage source, but code requires a minimal SDK version 3 wher

    In the manifest, you specify both the minimum version and the target version. So unless you've specified a minimum version of 1 or 2 (unlikely), code that requires a minimum version of 3 will be fine. Android 2.2 is the oldest version you're likely to encounter, and that's API level 8. I use API 9 (a.k.a. 2.3, a.k.a Gingerbread) as the minimum in a lot of programs because that's when Google finally got around to adding a several very useful things that have been in the standard Java API since day one.

    If you use API 9 as the minimum, you may still be able to conditionally use API 11 features. Obviously you can't call methods that don't exist, but sometimes constants get added in later APIs that would have been illegal arguments in earlier ones. In those cases, you can find out what API version your program is running on and conditonally use the new constants.

    If you need any more help, post the stack trace of your crash.
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. How to make this work?
    By Aceflare0 in forum New To Java
    Replies: 12
    Last Post: 02-16-2013, 07:05 AM
  2. Replies: 5
    Last Post: 01-23-2013, 11:37 AM
  3. Replies: 0
    Last Post: 10-28-2011, 07:35 PM
  4. Make it work !
    By PhQ in forum New To Java
    Replies: 6
    Last Post: 09-20-2010, 09:22 AM
  5. Replies: 0
    Last Post: 03-27-2010, 12:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •