在我的应用程序中,我将获取默认浏览器中可用的所有书签,并在列表视图中填充它。我想要的是当我点击特定的listItem(书签)时,它应该在默认浏览器中直接打开该书签。
String[] requestedColumns = { Browser.BookmarkColumns.TITLE,
Browser.BookmarkColumns.VISITS,
Browser.BookmarkColumns.BOOKMARK };
@SuppressWarnings("deprecation")
Cursor faves = managedQuery(Browser.BOOKMARKS_URI, requestedColumns,
Browser.BookmarkColumns.BOOKMARK + "=1", null,
Browser.BookmarkColumns.VISITS);
Log.d("Bookmarks", "Bookmarks count: " + faves.getCount());
int titleIdx = faves.getColumnIndex(Browser.BookmarkColumns.TITLE);
String url[] = new String[] {android.provider.Browser.BookmarkColumns.URL};
Log.d("SimpleBookmarks url", url[0]);
//int url_column_index = faves.getColumnIndexOrThrow(Browser.BookmarkColumns.URL);
faves.moveToFirst();
if (bookmark_check) {
while (!faves.isAfterLast()) {
Log.d("SimpleBookmarks", faves.getString(titleIdx));
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("bookmark", faves.getString(titleIdx));
map.put("url", "");
listitem.add(map);
faves.moveToNext();
}
}
Log.v("data", "" + listitem);
SimpleAdapter listitemAdapter = new SimpleAdapter(this, listitem,
R.layout.list_style, new String[] { "bookmark", "url" },
new int[] { R.id.topTextView, R.id.bottomTextView });
lv.setAdapter(listitemAdapter);
答案 0 :(得分:2)
终于得到了解决方案。
String[] requestedColumns = { Browser.BookmarkColumns.TITLE,
Browser.BookmarkColumns.URL };
@SuppressWarnings("deprecation")
final Cursor faves = managedQuery(Browser.BOOKMARKS_URI,
requestedColumns, Browser.BookmarkColumns.BOOKMARK + "=1",
null, null);
faves.moveToFirst();
int titleIdx = faves.getColumnIndex(Browser.BookmarkColumns.TITLE);
final int urlIdx = faves.getColumnIndex(Browser.BookmarkColumns.URL);
if (bookmark_check) {
while (!faves.isAfterLast()) {
faves.getString(urlIdx));
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("name", faves.getString(titleIdx));
map.put("phone no", faves.getString(urlIdx));
listitem.add(map);
faves.moveToNext();
}
}
SimpleAdapter listitemAdapter = new SimpleAdapter(this, listitem,
R.layout.list_style, new String[] { "name", "phone no" },
new int[] { R.id.topTextView, R.id.bottomTextView });
lv.setAdapter(listitemAdapter);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
RelativeLayout lr = (RelativeLayout) arg1;
TextView mText = (TextView) lr.getChildAt(1);
String st = mText.getText().toString();
if (!st.startsWith("https://") && !st.startsWith("http://")) {
st = "http://" + mText.getText().toString();
}
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(st));
startActivity(i);
}
});