【发布时间】:2010-11-18 20:23:42
【问题描述】:
我正在尝试在我的 android 活动中使用 jsoup (1.3.3) 解析一些 html。当我调用此代码时
Jsoup.connect("http://www.google.com").get();
它在 android 2.1 和 2.2 中运行良好,但在 1.6 中我得到一个“java.io.IOException: 403 Error loading URL”。
我正在使用模拟器对此进行测试,我注意到 admob 广告也未在 1.6 中显示,但它们在 2.0、2.1 和 2.2 中有效。
在 1.6 模拟器中使用网络浏览器确实有效,所以我很确定问题出在我的代码中。
在 1.6 中我需要一些额外的权限来访问互联网,而在 2.0+ 中不需要吗?
这是我的清单文件的结构,uses-permission标签的位置有什么影响吗?
<?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">
<application 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>
我尝试从头开始创建一个新项目,它只使用一个使用 Jsoup.connect() 方法的 hello world 屏幕,并且在同一个 1.6 模拟器上运行良好,所以它一定是代码问题,但我不能想办法。
【问题讨论】:
-
您的 AndroidManifest.xml 中有哪些权限?您是否也尝试过使用直接 HttpClient 来访问 URL(让 Jsoup 退出循环)?
-
代码
Document doc = Jsoup.connect("http://www.google.com").get(); Log.i("jsoup", doc.title());在带有<uses-permission android:name="android.permission.INTERNET" />和 jsoup-1.3.3.jar 的 1.6 模拟器上为我工作 -
您是否使用其他应用程序(例如默认浏览器)验证了网络在该模拟器实例中是否有效?可能想制作一个新的模拟器来确定。
标签: android permissions jsoup