Android urlconnection を使用して Web ページにアクセスしようとしていますが、jsoup を使用して解析することもできました。ただし、リストビューの行をクリックすると、ブラウザでリンクが開きません。これは私のコードと .xml です。私を助けてください。
logcat
06-21 14:40:07.428: E/AndroidRuntime(10510): FATAL EXCEPTION: main
06-21 14:40:07.428: E/AndroidRuntime(10510): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=Full story: Daily Mail }
06-21 14:40:07.428: E/AndroidRuntime(10510): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)
06-21 14:40:07.428: E/AndroidRuntime(10510): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
06-21 14:40:07.428: E/AndroidRuntime(10510): at android.app.Activity.startActivityForResult(Activity.java:3370)
06-21 14:40:07.428: E/AndroidRuntime(10510): at android.app.Activity.startActivityForResult(Activity.java:3331)
06-21 14:40:07.428: E/AndroidRuntime(10510): at android.app.Activity.startActivity(Activity.java:3566)
06-21 14:40:07.428: E/AndroidRuntime(10510): at android.app.Activity.startActivity(Activity.java:3534)
06-21 14:40:07.428: E/AndroidRuntime(10510): at com.omeja.bbcsport.BBCActivity.onListItemClick(BBCActivity.java:234)
06-21 14:40:07.428: E/AndroidRuntime(10510): at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
06-21 14:40:07.428: E/AndroidRuntime(10510): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
06-21 14:40:07.428: E/AndroidRuntime(10510): at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
06-21 14:40:07.428: E/AndroidRuntime(10510): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2749)
06-21 14:40:07.428: E/AndroidRuntime(10510): at android.widget.AbsListView$1.run(AbsListView.java:3423)
06-21 14:40:07.428: E/AndroidRuntime(10510): at android.os.Handler.handleCallback(Handler.java:725)
06-21 14:40:07.428: E/AndroidRuntime(10510): at android.os.Handler.dispatchMessage(Handler.java:92)
06-21 14:40:07.428: E/AndroidRuntime(10510): at android.os.Looper.loop(Looper.java:137)
06-21 14:40:07.428: E/AndroidRuntime(10510): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-21 14:40:07.428: E/AndroidRuntime(10510): at java.lang.reflect.Method.invokeNative(Native Method)
06-21 14:40:07.428: E/AndroidRuntime(10510): at java.lang.reflect.Method.invoke(Method.java:511)
06-21 14:40:07.428: E/AndroidRuntime(10510): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-21 14:40:07.428: E/AndroidRuntime(10510): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-21 14:40:07.428: E/AndroidRuntime(10510): at dalvik.system.NativeStart.main(Native Method)
コード
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
//
//
Document doc;
try {
// doc = Jsoup.connect(url1).get();
// String title = doc.title();
// Elements links = doc.getElementsByClass("external-link");
doc = Jsoup.parse(result, url1);
Elements links = doc.select("h2 ~ p");
// Elements links = doc.select("h2.cross-head");
// Elements links = doc.select("a.external-link");
// Elements media = doc.select("[src]");
// Elements imports = doc.select("link[href]");
//
//
for (Element link : links) {
Elements tableDatas = link.getElementsByTag("p");
//Elements tableDatas2 = link.getElementsByTag("a");
if (tableDatas.hasText()) {
String rowData = tableDatas.text();
// rowData2 = tableDatas2.text();
//if (!tableRowStrings.contains(rowData)) {
tableRowStrings.add(rowData);
//}
}
//
}
//
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
BBCActivity.this, android.R.layout.simple_list_item_1,
tableRowStrings);
setListAdapter(adapter);
//
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//
}
//
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
// Do something when a list item is clicked
// String item = (String) getListAdapter().getItem(position);
Uri uri = Uri.parse((String) tableRowStrings.get(position));
// Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show();
//
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);
}
マニフェスト
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-feature />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.omeja.bbcsport.BBCActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>