开发者

Internet Access not working in Android 1.6, but works in 2.0/2.1/2.2

开发者 https://www.devze.com 2023-01-26 00:27 出处:网络
I\'m trying to parse some html using jsoup (1.3.3) in my android activity. When I call this code Jsoup.connect(\"http://www.google.com\").get();

I'm trying to parse some html using jsoup (1.3.3) in my android activity. When I call this code

Jsoup.connect("http://www.google.com").get();

It works fine in android 2.1 and 2.2 but in 1.6 I get a "java.io.IOException: 403 Error loading URL".

I'm using the emulator to test this and I've noticed that admob ads are also not showing in 1.6 but they work in 2.0, 2.1 and 2.2.

Using the web browser in the 1.6 emulator does work so I'm pretty confident the problem is in my code somewhere.

Is there some extra permission I need for internet access in 1.6 that you don't need in 2.0+?

This is how my manifest file is structured, does the position of the uses-permission tag have any effect?

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.foo.bar"
  android:versionCode="1"
  android:versionName="1.0"
  android:installLocation="auto">

<ap开发者_JAVA百科plication android:icon="@drawable/icon" 
android:label="@string/app_name" 
android:theme="@android:style/Theme.NoTitleBar" 
android:name="blahblah" 
android:description="@string/app_desc">

    <activity android:label="@string/app_name" android:name=".activities.MainMenu">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

<activity android:name=".activities.FullList" android:label="@string/app_name"/>

<!-- The application's publisher ID assigned by AdMob -->
<meta-data android:value="blahblahblah" android:name="ADMOB_PUBLISHER_ID" />

</application>
<uses-sdk android:minSdkVersion="4"/>

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

</manifest>

I've tried creating a new project from scratch with just a hello world screen that uses the Jsoup.connect() method and that works fine on the same 1.6 emulator, so it must be a code problem but I can't figure it out.


JSOUP internally uses HttpURLConnection. Here is the line throwing exception.

The internet connection is OK (or else it would throw exception earlier) and you are getting a reply from server which is: 403 HTTP FORBIDDEN

Is there some kind of login in place? Do check that you can open the same URL in browser on the same device/emulator.


Try inserting /uses-sdk near the end of the script or try deleting /uses-permission with each surrounded with angle brackets


I've tried creating a new project from scratch with just a hello world screen that uses the Jsoup.connect() method and that works fine on the same 1.6 emulator, so it must be a code problem but I can't figure it out.

Try putting a test usage of this early in your application startup (or if that causes an ANR timeout, add a "test" button)

Make a copy of your application and comment a lot of things out

Somewhere between your minimal test which works and your full application which doesn't, there lies an important difference. Recursively divide the difference and conquer it...

0

精彩评论

暂无评论...
验证码 换一张
取 消