我正在尝试使用 ADT 使用以下代码在 android 上获取 google pagerank,但它在 BufferedReader 行上给出了 NetworkOnMainThreadException 。
String url = "http://toolbarqueries.google.com/tbr?client=navclient-auto&hl=en&"
+ "ch=6" + hash + "&ie=UTF-8&oe=UTF-8&features=Rank&q=info:" + domain;
URLConnection conn = new URL(url).openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String input;
while ((input = br.readLine()) != null) {
result = input.substring(input.lastIndexOf(":") + 1);
}
顺便说一句,我在 PC java 项目上尝试了相同的代码,它工作正常。我也对 AndroidManifest.xml 给予以下许可。
<uses-permission android:name="android.permission.INTERNET"></uses-permission>