Android - Browser.BookmarkColumns无法在Zxing Library

时间:2015-11-30 10:42:02

标签: android qr-code zxing

我正在用zxing库开发应用程序。我把zxing项目导入了我的工作场所。在导入时,我遇到了一个问题。            Browser.BookmarkColumns无法解析或不是类型。

以下是提供的代码和屏幕截图。一点点暗示就够了......

BookmarkPickerActivity.java

public final class BookmarkPickerActivity extends ListActivity {

private static final String TAG = BookmarkPickerActivity.class.getSimpleName();

private static final String[] BOOKMARK_PROJECTION = { Browser.BookmarkColumns.TITLE, Browser.BookmarkColumns.URL };

static final int TITLE_COLUMN = 0;
static final int URL_COLUMN = 1;

private static final String BOOKMARK_SELECTION = Browser.BookmarkColumns.BOOKMARK + " = 1 AND " + Browser.BookmarkColumns.URL + " IS NOT NULL";

private Cursor cursor;

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    cursor = getContentResolver().query(content://com.android.chrome.browser/bookmarks, BOOKMARK_PROJECTION, BOOKMARK_SELECTION, null, null);
    if (cursor == null) {
        Log.w(TAG, "No cursor returned for bookmark query");
        finish();
        return;
    }
    setListAdapter(new BookmarkAdapter(this, cursor));
}

@Override
protected void onDestroy() {
    if (cursor != null) {
        cursor.close();
    }
    super.onDestroy();
}

@Override
protected void onListItemClick(ListView l, View view, int position, long id) {
    if (!cursor.isClosed() && cursor.moveToPosition(position)) {
        Intent intent = new Intent();
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        intent.putExtra(Browser.BookmarkColumns.TITLE, cursor.getString(TITLE_COLUMN));
        intent.putExtra(Browser.BookmarkColumns.URL, cursor.getString(URL_COLUMN));
        setResult(RESULT_OK, intent);
    } else {
        setResult(RESULT_CANCELED);
    }
    finish();
}
}

enter image description here

3 个答案:

答案 0 :(得分:6)

Most things related to Bookmarks were removed in API Level 23(Android 6.0)。您将compileSdkVersion(也称为Eclipse中的构建目标)设置为API级别23.您可以将compileSdkVersion放到较低的位置以通过此错误,但代码本身不适用于Android 6.0 +。

答案 1 :(得分:2)

选项1:在build.gradle文件上更改compileSdkVersion 23到22以解决此问题..

选项2:使用反射方法在compileSdkVersion> = 23中获取浏览器历史记录。

答案 2 :(得分:0)

使用已更新为api 25 的新版Zxing