gpt4 book ai didi

java - 从浏览器历史记录中提取 URL 时显示无法解析符号 'BookmarkColumns'

转载 作者:搜寻专家 更新时间:2023-11-01 09:36:12 25 4
gpt4 key购买 nike

我正在尝试从浏览器历史记录中提取 URL。我找到了下面的代码并尝试实现它。但问题是它在 BookmarkColumnsBOOKMARKS_URInoicon 中给出了错误。

我在 API 级别 16、23、25 中试过这个。但是错误解决了。它总是说“无法解析符号‘BookmarkColumns’”

请帮我解决这个...

import android.content.ContentResolver;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.provider.Browser;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;


public class MainActivity extends AppCompatActivity {

private ArrayList<String> titles;
private ArrayList<String> urls;
private ArrayList<Bitmap> bitmaps;
private ContentResolver cr;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
createLists();
}

protected void onResume() {
super.onResume();
getBH();
showHistoryBookmarks();

}

public void createLists() {
titles = new ArrayList<String>();
urls = new ArrayList<String>();
bitmaps = new ArrayList<Bitmap>();

}

public void getBH() {
Bitmap icon;
cr = getContentResolver();
String order = Browser.BookmarkColumns.DATE + " DESC";
String[] projection = {Browser.BookmarkColumns.TITLE, Browser.BookmarkColumns.URL, Browser.BookmarkColumns.FAVICON};
//String selection=projection[0]+"=?";
//String args[]={"Google"};
Cursor rows = cr.query(Browser.BOOKMARKS_URI, projection, null, null, order);
if (rows.getCount() > 0) {
while (rows.moveToNext()) {
//read title
String title = rows.getString(rows.getColumnIndex(projection[0]));
//read url
String url = rows.getString(rows.getColumnIndex(projection[1]));
//read icon
byte[] bicon = rows.getBlob(rows.getColumnIndex(projection[2]));
if (bicon != null) {
//convert blob image data to Bitmap
icon = BitmapFactory.decodeByteArray(bicon, 0, bicon.length);

} else {
//default icon for history and bookmarks that do not icons
icon = BitmapFactory.decodeResource(getResources(), R.drawable.noicon);
}
//add to lists
addToList(title, url, icon);
}
//close the cursor
rows.close();
}


}


public void addToList(String title, String url, Bitmap bitmap) {

titles.add(title);
urls.add(url);
bitmaps.add(bitmap);

}


public void showHistoryBookmarks() {
ListView l = (ListView) findViewById(R.id.hb_list);
if (l != null) {
if (titles.size() > 0) {
ListAdapterModel aa = new ListAdapterModel(this, R.layout.listlayout, R.id.hbtitle, titles, urls, bitmaps);
l.setAdapter(aa);
} else {
Toast.makeText(this, "This is no bookmark or history.", Toast.LENGTH_SHORT).show();
}
}

}
}

最佳答案

试试这些 chrome history API .阅读文档并尝试一下。我没试过。但思想将是insperation。

关于java - 从浏览器历史记录中提取 URL 时显示无法解析符号 'BookmarkColumns',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43045460/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com